Code example for ByteArrayOutputStream

Methods: size, toByteArray

0
    public static int headerSize() { 
        return MAGIC_LEN + 4 * 2;
    } 
 
    public void writeHeader(OutputStream out) throws IOException {
        ByteArrayOutputStream header = new ByteArrayOutputStream();
        DataOutputStream d = new DataOutputStream(header);
        d.write(magic, 0, MAGIC_LEN);
        d.writeInt(version);
        d.writeInt(compatibleVersion);
        d.close();
        out.write(header.toByteArray(), 0, header.size());
    } 
 
    public boolean isValidMagicHeader() { 
        return Arrays.equals(MAGIC_HEADER, magic);
    } 
 
    public static SnappyCodec readHeader(InputStream in) throws IOException {
        DataInputStream d = new DataInputStream(in);
        byte[] magic = new byte[MAGIC_LEN];