java/hybridse-sdk/src/main/java/com/_4paradigm/hybridse/sdk/SerializableByteBuffer.java
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();

        // object stream is backed by block stream, thus read bytes
        // operations should be buffered to ensure exact bytes are read
        DataInputStream wrappedInStream = new DataInputStream(in);

        int capacity = wrappedInStream.readInt();
        boolean isDirect = wrappedInStream.readBoolean();
        if (isDirect) {
            buffer = ByteBuffer.allocateDirect(capacity);
        } else {
            buffer = ByteBuffer.allocate(capacity);
        }
        byte[] bytes;
        if (buffer.hasArray()) {
            bytes = buffer.array();
        } else {
            bytes = new byte[capacity];
        }

        try {
            wrappedInStream.readFully(bytes, 0, capacity);
        } catch (IOException e) {
            throw new IOException("Byte buffer stream corrupt, " + "expect buffer bytes: " + capacity, e);
        }
        if (!buffer.hasArray()) { // maybe direct
            buffer.put(bytes, 0, capacity);
            buffer.rewind();
        }
        int endTag = wrappedInStream.readInt();
        if (endTag != MAGIC_END_TAG) {
            throw new IOException("Byte buffer stream corrupt");
        }
    }
/**
     * Serialization method to load the ByteBuffer.
     *
     * @throws IOException throw when fail to read by DataInputStream
     * @throws ClassNotFoundException throw when class not found
     */
Serialization method to load the ByteBuffer.
@throws IOException throw when fail to read by DataInputStream
@throws ClassNotFoundException throw when class not found
Serialization method to load the ByteBuffer . @throws IOException throw when fail to read by DataInputStream @throws ClassNotFoundException throw when class not found
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        DataInputStream wrappedInStream = new DataInputStream(in);
        int capacity = wrappedInStream.readInt();
        boolean isDirect = wrappedInStream.readBoolean();
        if (isDirect) {
            buffer = ByteBuffer.allocateDirect(capacity);
        } else {
            buffer = ByteBuffer.allocate(capacity);
        }
        byte[] bytes;
        if (buffer.hasArray()) {
            bytes = buffer.array();
        } else {
            bytes = new byte[capacity];
        }
        try {
            wrappedInStream.readFully(bytes, 0, capacity);
        } catch (IOException e) {
            throw new IOException("Byte buffer stream corrupt, " + "expect buffer bytes: " + capacity, e);
        }
        if (!buffer.hasArray()) { 
            buffer.put(bytes, 0, capacity);
            buffer.rewind();
        }
        int endTag = wrappedInStream.readInt();
        if (endTag != MAGIC_END_TAG) {
            throw new IOException("Byte buffer stream corrupt");
        }
    }
private void readObject ( java . io . ObjectInputStream in ) throws IOException , ClassNotFoundException { in . defaultReadObject ( ) ; DataInputStream wrappedInStream = new DataInputStream ( in ) ; int capacity = wrappedInStream . readInt ( ) ; boolean isDirect = wrappedInStream . readBoolean ( ) ; if ( isDirect ) { buffer = ByteBuffer . allocateDirect ( capacity ) ; } else { buffer = ByteBuffer . allocate ( capacity ) ; } byte [ ] bytes ; if ( buffer . hasArray ( ) ) { bytes = buffer . array ( ) ; } else { bytes = new byte [ capacity ] ; } try { wrappedInStream . readFully ( bytes , 0 , capacity ) ; } catch ( IOException e ) { throw new IOException ( "Byte buffer stream corrupt, " + "expect buffer bytes: " + capacity , e ) ; } if ( ! buffer . hasArray ( ) ) { buffer . put ( bytes , 0 , capacity ) ; buffer . rewind ( ) ; } int endTag = wrappedInStream . readInt ( ) ; if ( endTag != MAGIC_END_TAG ) { throw new IOException ( "Byte buffer stream corrupt" ) ; } }
Serialization method to load the ByteBuffer.
Serialization method to load the ByteBuffer .
// object stream is backed by block stream, thus read bytes // operations should be buffered to ensure exact bytes are read // maybe direct