Java ByteArrayOutputStream Write loadStream(InputStream in, String encoding)

Here you can find the source of loadStream(InputStream in, String encoding)

Description

load Stream

License

Open Source License

Declaration

public static String loadStream(InputStream in, String encoding) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static String loadStream(InputStream in) throws IOException {
        return loadStream(in, "UTF-8");
    }/*from  w w w  .  j  a  va 2 s .  c o  m*/

    public static String loadStream(InputStream in, String encoding) throws IOException {
        if (encoding == null)
            encoding = "UTF-8";

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        while (true) {
            int readlen = in.read(buf);
            if (readlen == -1)
                break;
            bos.write(buf, 0, readlen);
        }
        return bos.toString(encoding);
    }
}

Related

  1. loadBinFile(java.io.File f)
  2. loadFully(final InputStream aStream)
  3. loadIfileAsBytes(final IFile ifile)
  4. loadIntoMemory(InputStream is)
  5. loadProbe(InputStream in, int buffSize)
  6. readAll(File file)
  7. readAll(InputStream aInputStream)
  8. readAll(InputStream bytes)
  9. readAll(InputStream bytes, int bufferSize)