Skip to content

Instantly share code, notes, and snippets.

@wangyingang
Created July 13, 2015 18:06
Show Gist options
  • Save wangyingang/6b81394c9c32bc6e5cc7 to your computer and use it in GitHub Desktop.
Save wangyingang/6b81394c9c32bc6e5cc7 to your computer and use it in GitHub Desktop.

Revisions

  1. wangyingang created this gist Jul 13, 2015.
    24 changes: 24 additions & 0 deletions Utils.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    public class Utils {

    public static byte[] getBytes(InputStream is) throws IOException {

    int len;
    int size = 1024;
    byte[] buf;

    if (is instanceof ByteArrayInputStream) {
    size = is.available();
    buf = new byte[size];
    len = is.read(buf, 0, size);
    } else {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    buf = new byte[size];
    while ((len = is.read(buf, 0, size)) != -1)
    bos.write(buf, 0, len);
    buf = bos.toByteArray();
    }
    return buf;
    }


    }