Here you can find the source of getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess)
public static byte[] getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess) throws IOException
//package com.java2s; /******************************************************************************* * Copyright ? Microsoft Open Technologies, Inc. * * All Rights Reserved/*from w ww . j a v a 2s.c o m*/ * * 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 * * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. * * See the Apache License, Version 2.0 for the specific language * governing permissions and limitations under the License. ******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; public class Main { public static byte[] getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess) throws IOException { InputStream is = conn.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(buff, 0, buff.length)) != -1) { baos.write(buff, 0, bytesRead); } byte[] bytes = baos.toByteArray(); baos.close(); return bytes; } }