Java InputStream Read Line readLineSet(InputStream stream)

Here you can find the source of readLineSet(InputStream stream)

Description

read a set of string lines from input stream and close it

License

Open Source License

Parameter

Parameter Description
inputStream a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static Set<String> readLineSet(InputStream stream) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2012 Nikita Zhiltsov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html//  w  w w  .  j  av a  2s  .  co  m
 * 
 * Contributors:
 *     Nikita Zhiltsov - initial API and implementation
 *     Azat Khasanshin - implementation
 ******************************************************************************/

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

import java.util.HashSet;

import java.util.Set;

public class Main {
    /**
     * read a set of string lines from input stream and close it
     * 
     * @param inputStream
     * @return
     * @throws IOException
     */
    public static Set<String> readLineSet(InputStream stream) throws IOException {
        Set<String> values = new HashSet<String>();
        try {
            LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(stream));
            String line = null;
            while ((line = lineReader.readLine()) != null) {
                values.add(line);
            }
            return values;
        } finally {
            stream.close();
        }
    }
}

Related

  1. readLines(InputStream stream)
  2. readLines(InputStream stream)
  3. readLines(InputStream stream)
  4. readLines(InputStream stream, String charset)
  5. readLinesCommon(InputStream in)
  6. readLinesStream(InputStream is, boolean trim)
  7. readLineString(InputStream is)
  8. readLineStringBuilder(InputStream is)
  9. readLineStringConcat(InputStream is)