Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.ByteArrayOutputStream;

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

public class Main {
    public static String readInputStreamAsString(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] bytes = new byte[4096];
        int lenRead;
        while ((lenRead = is.read(bytes)) != -1) {
            if (lenRead > 0)
                baos.write(bytes, 0, lenRead);
        }

        if (baos.size() > 0)
            return baos.toString("utf-8");
        return null;
    }
}