Java UTF8 InputStream Read loadUTF8Stream(InputStream stream)

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

Description

load UTF Stream

License

Apache License

Declaration

public static String loadUTF8Stream(InputStream stream) throws IOException 

Method Source Code

//package com.java2s;
/*//from   w w w  .  ja v a 2  s. c om
   Copyright 2014-2016 PetaByte Research Ltd.
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;

import java.util.Scanner;

public class Main {
    public static String loadUTF8Stream(InputStream stream) throws IOException {
        if (null == stream) {
            throw new FileNotFoundException();
        }
        StringBuffer buf = new StringBuffer();
        Scanner scanner = new Scanner(stream, "UTF8");
        while (scanner.hasNextLine()) {
            buf.append(scanner.nextLine());
            buf.append("\n");
        }
        scanner.close();
        return buf.toString();
    }
}

Related

  1. LoadUTF8(InputStream stream)