Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

public class Main {

    public static String getStringFromInput(InputStream is) throws IOException {
        ByteArrayOutputStream byteOus = new ByteArrayOutputStream();
        byte[] tmp = new byte[1024];
        int size = 0;
        while ((size = is.read(tmp)) != -1) {
            byteOus.write(tmp, 0, size);
        }
        byteOus.flush();
        is.close();
        return byteOus.toString();
    }

    public static void close(Closeable close) {
        try {
            if (close != null) {
                close.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}