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 android.util.Log;
import java.io.ByteArrayOutputStream;

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

public class Main {
    final static String TAG = "OTUtils.otclient";

    /**
     * read inputstream and return the byte array
     * @param inputStream
     * @return
     * @throws IOException
     */
    public static byte[] readBytesFromInputStream(InputStream inputStream) throws IOException {
        if (inputStream == null) {
            Log.e(TAG, "invalid inputStream");
            return null;
        }

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int read = inputStream.read();
        while (read != -1) {
            byteArrayOutputStream.write(read);
            read = inputStream.read();
        }

        return byteArrayOutputStream.toByteArray();
    }
}