Java Byte Array from getBytes(int length, InputStream inStream)

Here you can find the source of getBytes(int length, InputStream inStream)

Description

get Bytes

License

Apache License

Parameter

Parameter Description
length is length of file
inStream input stream of input file

Return

array of byte representing a input file

Declaration

private static byte[] getBytes(int length, InputStream inStream) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

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

public class Main {
    /**//from  ww  w .  j a v a  2s .c  o  m
     * @param length is length of file
     * @param inStream input stream of input file
     * @return array of byte representing a input file
     */
    private static byte[] getBytes(int length, InputStream inStream) {
        int bytesRead = 0;
        byte[] content = new byte[length];
        while (bytesRead < length) {
            int result;
            try {
                result = inStream.read(content, bytesRead, length - bytesRead);
                if (result == -1)
                    break;
                bytesRead += result;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return content;
    }
}

Related

  1. getBytes(final InputStream is)
  2. getBytes(final Serializable obj)
  3. getBytes(final String data, String charset)
  4. getBytes(final String data, String charset)
  5. getBytes(final String value, final String characterEncoding)
  6. getBytes(int value)
  7. getBytes(String content)
  8. getBytes(String data, String encoding)
  9. getBytes(String defaultPlain)