Method to convert a Collection of Binary to a byte array.

@param binaryList Collection containing Binary elements.
@throws IOException If unable to write binary to bytes, e.g. on buffer overflow.
@return Array of bytes.
334198
public static byte[] fromBinaryCollection(Collection<Binary> binaryList) throws IOException {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
             BigEndianBinaryWriter writer = new BigEndianBinaryWriter(baos)) {
            writer.writeInt(binaryList.size());
            for (Binary binary : binaryList) {
                writer.writeInt(binary.length());
                writer.writeBinary(binary);
            }
            return baos.toByteArray();
        }
    }
117757
byte[] binary(String name, String profile, String label, String path)
			throws IOException {
		return binary(null, name, profile, label, path);
	}
310881
public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream answer = new ByteArrayOutputStream();
        // reading the content of the file within a byte buffer
        byte[] byteBuffer = new byte[8192];
        int nbByteRead /* = 0*/;
        try {
            while ((nbByteRead = is.read(byteBuffer)) != -1) {
                // appends buffer
                answer.write(byteBuffer, 0, nbByteRead);
            }
        } finally {
            closeWithWarning(is);
        }
        return answer.toByteArray();
    }
487266
public MessageAttributeValue withBinaryListValues(java.util.Collection<java.nio.ByteBuffer> binaryListValues) {
        setBinaryListValues(binaryListValues);
        return this;
    }
1170034
public static byte[] convertObjectToByteArray(Object o) throws IOException{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(o);
		
		return bos.toByteArray();
	}
1326175
protected byte[] byteBufferToByteArray() {
        if (byteBuffer.hasArray()) {
            return byteBuffer.array();
        } else {
            final byte[] byteArray = new byte[byteBuffer.remaining()];
            byteBuffer.get(byteArray);
            return byteArray;
        }
    }
1132876
public WebSocketInputStream initBinary()
    throws IOException
  {
    if (_binaryIn == null) {
      _binaryIn = new WebSocketInputStream(this);
    }

    _binaryIn.init();

    return _binaryIn;
  }
728237
public static byte[] toByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            byte[] b = new byte[BUFFER_SIZE];
            int n = 0;
            while ((n = is.read(b)) != -1) {
                output.write(b, 0, n);
            }
            return output.toByteArray();
        } finally {
            output.close();
        }
    }
308746
public java.util.List<java.nio.ByteBuffer> getBinaryListValues() {
        if (binaryListValues == null) {
            binaryListValues = new com.amazonaws.internal.SdkInternalList<java.nio.ByteBuffer>();
        }
        return binaryListValues;
    }
517806
public static final byte[] readAllBytes(InputStream is) throws IOException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buf = new byte[4096];
        int rc = is.read(buf);
        while (rc != -1)
        {
            baos.write(buf, 0, rc);
            rc = is.read(buf);
        }
        return baos.toByteArray();
    }
1054484
public JSONObject readContentFromBinaryFile(File binaryFile) throws Exception {
    PlistFileUtils util = new PlistFileUtils(binaryFile);
    return util.toJSON();
  }
942477
public static byte[] convertStringToBinary(String text,String encoding)
    {
        byte[] data=null;
        if(text!=null)
        {
            if(text.length()==0)
            {
                data=new byte[0];
            }
            else
            {
                //get logger
                LoggerManager loggerManager=LoggerManager.getInstance();
                Logger logger=loggerManager.getLogger();

                String encodingToUse=encoding;
                if((encodingToUse!=null)&&(encodingToUse.length()>0))
                {
                    try
                    {
                        data=text.getBytes(encodingToUse);
                    }
                    catch(UnsupportedEncodingException exception)
                    {
                        logger.logError(new Object[]{"Unable to convert text to binary using encoding: ",encodingToUse," using default system encoding."},exception);
                    }
                }
                
                if(data==null)
                {
                    encodingToUse=IOHelper.getDefaultEncoding();

                    try
                    {
                        data=text.getBytes(encodingToUse);
                    }
                    catch(UnsupportedEncodingException exception)
                    {
                        logger.logError(new Object[]{"Unable to convert text to binary using default encoding: ",encodingToUse},exception);
                        
                        throw new FaxException("Unable to convert text to binary using encoding: "+encodingToUse,exception);
                    }
                }
            }
        }
        
        return data;
    }
433815
public static byte[] unboxBytes(Collection<Byte> coll) {
    byte[] res = new byte[coll.size()];
    int i = 0;
    for (Byte elem : coll)
      res[i++] = elem;
    return res;
  }
952440
public byte[] getContentAsByteArray() {
        if (content == null) {
            try {
                content = IOHelper.byteArrayFromStream(is);
            } catch (IOException e) {
                throw new RuntimeException("IOException buffering binary data",
                        e);
            }
            is = null;
        }
        return content;
    }
540109
private static byte[] bitSetToByteArray(BitSet bitSet) {

    while (bitSet.length() % 8 != 0) { bitSet.set(bitSet.length(), true); }
    
    byte[] array = new byte[bitSet.length()/8];

    for (int i = 0; i < array.length; i++) {
      int offset = i * 8;

      int index = 0;
      for (int j = 0; j < 8; j++) {
        index <<= 1;        
        if (bitSet.get(offset+j)) { index++; }
      }

      array[i] = (byte)(index - 128);
    }

    return array;
  }
251941
function BinaryStream(arrayBuffer) {
    this._arrayBuffer = arrayBuffer || new ArrayBuffer(1024);
    this._dataView = new DataView(this._arrayBuffer);
    this._pos = 0;
    this._canExpand = !arrayBuffer;
}
943749
private byte[] receiveBytes(InputStream is) throws IOException {
        byte[] buffer = new byte[8192];
        int len = (is.read(buffer));
        if (len < 1) {
            throw new IOException("receiveBytes read " + len + " bytes.");
        }
        return Arrays.copyOf(buffer, len);
    }