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.input; 018 019import java.io.InputStream; 020import java.nio.charset.Charset; 021 022import org.apache.commons.geometry.io.core.AbstractGeometryIOMetadata; 023 024/** {@link GeometryInput} implementation that wraps an {@link InputStream}. 025 */ 026public class StreamGeometryInput extends AbstractGeometryIOMetadata 027 implements GeometryInput { 028 029 /** Input stream. */ 030 private final InputStream in; 031 032 /** Construct a new instance that reads from the given input stream with 033 * no configured file name or charset. 034 * @param in input stream 035 */ 036 public StreamGeometryInput(final InputStream in) { 037 this(in, null, null); 038 } 039 040 /** Construct a new instance that reads from the given input stream with the 041 * configured file name but no charset. 042 * @param in input stream 043 * @param fileName input file name; may be null 044 */ 045 public StreamGeometryInput(final InputStream in, final String fileName) { 046 this(in, fileName, null); 047 } 048 049 /** Construct a new instance that reads from the given input stream with the configured 050 * file name and charset. 051 * @param in input stream 052 * @param fileName input file name; may be null 053 * @param charset input charset; may be null 054 */ 055 public StreamGeometryInput(final InputStream in, final String fileName, final Charset charset) { 056 super(fileName, charset); 057 058 this.in = in; 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 public InputStream getInputStream() { 064 return in; 065 } 066}