001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.geometry.io.core.output; 018 019import java.io.OutputStream; 020import java.nio.charset.Charset; 021 022import org.apache.commons.geometry.io.core.AbstractGeometryIOMetadata; 023 024/** {@link GeometryOutput} implementation that wraps an {@link OutputStream}. 025 */ 026public class StreamGeometryOutput extends AbstractGeometryIOMetadata 027 implements GeometryOutput { 028 029 /** Output stream. */ 030 private final OutputStream out; 031 032 /** Construct a new instance that writes to the given output stream with 033 * no configured file name or charset. 034 * @param out output stream 035 */ 036 public StreamGeometryOutput(final OutputStream out) { 037 this(out, null, null); 038 } 039 040 /** Construct a new instance that writes to the given output stream with the 041 * configured file name but no charset. 042 * @param out output stream 043 * @param fileName output file name; may be null 044 */ 045 public StreamGeometryOutput(final OutputStream out, final String fileName) { 046 this(out, fileName, null); 047 } 048 049 /** Construct a new instance that writes to the given output stream with the configured 050 * file name and charset. 051 * @param out output stream 052 * @param fileName output file name; may be null 053 * @param charset output charset; may be null 054 */ 055 public StreamGeometryOutput(final OutputStream out, final String fileName, final Charset charset) { 056 super(fileName, charset); 057 058 this.out = out; 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 public OutputStream getOutputStream() { 064 return out; 065 } 066}