Example usage for java.io ObjectInputStream read

List of usage examples for java.io ObjectInputStream read

Introduction

In this page you can find the example usage for java.io ObjectInputStream read.

Prototype

public int read(byte b[]) throws IOException 

Source Link

Document

Reads some number of bytes from the input stream and stores them into the buffer array b.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.write("java2s.com".getBytes());
    out.close();// w w w .  jav  a2  s. c  o  m

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeLong(1111111111111L);/* w  w w  . j  a  v  a2  s .  c  o m*/
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:mitm.application.djigzo.james.EncryptedContainer.java

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, EncryptorException {
    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }/*from  w w  w  . j  a v  a  2  s.  co m*/

    byte[] encrypted = new byte[in.readInt()];

    in.read(encrypted);

    value = (T) SerializationUtils.deserialize(getEncryptor().decrypt(encrypted));
}

From source file:it.unimi.dsi.util.ImmutableExternalPrefixMap.java

private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
    s.defaultReadObject();//  www  .  j  a va 2s  .  co m
    if (selfContained) {
        final File temp = File.createTempFile(this.getClass().getName(), ".dump");
        temp.deleteOnExit();
        tempDumpStreamFilename = temp.toString();
        // TODO: propose Jakarta CopyUtils extension with length control and refactor.
        FileOutputStream fos = new FileOutputStream(temp);
        final byte[] b = new byte[64 * 1024];
        int len;
        while ((len = s.read(b)) >= 0)
            fos.write(b, 0, len);
        fos.close();
        dumpStream = new InputBitStream(temp, (int) (blockSize / 8));
    }
}

From source file:org.apache.flink.api.common.accumulators.ListAccumulator.java

@Override
public void read(ObjectInputStream in) throws IOException {
    int numItems = in.readInt();
    for (int i = 0; i < numItems; i++) {
        int len = in.readInt();
        byte[] obj = new byte[len];
        in.read(obj);
        localValue.add(obj);/*from   w w  w  . j  av  a2  s .c  o  m*/
    }
}

From source file:org.mule.DefaultMuleMessage.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();/*w w  w .j  av a2  s  .co  m*/

    boolean payloadWasSerialized = in.readBoolean();
    if (payloadWasSerialized) {
        payload = in.readObject();
    } else {
        int payloadSize = in.readInt();
        byte[] serializedPayload = new byte[payloadSize];
        in.read(serializedPayload);
        payload = serializedPayload;
    }
    inboundAttachments = deserializeAttachments((Map<String, SerializedDataHandler>) in.readObject());
    outboundAttachments = deserializeAttachments((Map<String, SerializedDataHandler>) in.readObject());
}