Code example for ByteArrayOutputStream

Methods: sizetoByteArraywritewrite

0
    GrandstreamBinaryProfileWriter(GrandstreamPhone phone) {
        super(phone);
    } 
 
    public void write(OutputStream wtr) {
        ByteArrayOutputStream inmemory = new ByteArrayOutputStream();
        setOutputStream(inmemory);
        write(); 
        writeBody(inmemory, wtr);
    } 
 
    void writeBody(ByteArrayOutputStream inmemory, OutputStream wtr) {
        try { 
            finalizeBody(inmemory);
            byte[] body = inmemory.toByteArray();
            writeHeader(wtr, body);
            wtr.write(body);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } 
    } 
 
    @Override 
    protected void writeLineEntry(String name, String value) {
        String line = name + '=' + nonNull(value) + ET;
        writeString(line);
    } 
 
    void finalizeBody(ByteArrayOutputStream wtr) throws IOException {
        wtr.write("gnkey=0b82".getBytes());
        if (wtr.size() % 2 == 1) {
            wtr.write('\000');
        } 
    } 
 
    void writeHeader(OutputStream wtr, byte[] body) throws IOException {
        byte[] gsheader = new byte[] {
Experience pair programming with AI  Get Codota for Java