Java URL Load readHttpBytes(String url)

Here you can find the source of readHttpBytes(String url)

Description

read Http Bytes

License

Creative Commons License

Declaration

public static byte[] readHttpBytes(String url) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.*;
import java.net.URL;

public class Main {
    public static byte[] readHttpBytes(String url) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream httpIn = new URL(url).openStream();
        byte[] buffer = new byte[1024];
        int n;/*from   w ww. j  a va 2s.  c  o m*/

        while ((n = httpIn.read(buffer)) != -1)
            baos.write(buffer, 0, n);

        httpIn.close();
        return baos.toByteArray();

    }
}

Related

  1. readFromUrl(String urlString)
  2. readFromUrl(String urlText)
  3. readFromUrl(URL url)
  4. readFromURL(URL url)
  5. readGOMappingFile(URL filename, Set secondAttributeList)
  6. readHttpFile(final String urlStr)
  7. readInteger(URL src, int radix)
  8. readJsonFromUrl(String urlString)
  9. readLines(final String url)

  10. HOME | Copyright © www.java2s.com 2016