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 ( ) ; } }
Method to convert a Collection of Binary to a byte array .