Example usage for java.io ObjectInputStream readFully

List of usage examples for java.io ObjectInputStream readFully

Introduction

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

Prototype

public void readFully(byte[] buf, int off, int len) throws IOException 

Source Link

Document

Reads bytes, blocking until all bytes are read.

Usage

From source file:Main.java

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

    String s = "Hello World from java2s.com";

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeUTF(s);/* w w w . jav  a 2s. co m*/
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print from index 0 to 7
    byte[] b = new byte[13];
    ois.readFully(b, 0, 7);
    String array = new String(b);
    System.out.println(array);
    ois.close();

}

From source file:com.jaspersoft.jasperserver.api.metadata.common.domain.util.DataContainerStreamUtil.java

public static void readObjectByteData(ObjectInputStream objectStream, int size, OutputStream outStream)
        throws IOException {
    byte[] buffer = new byte[READ_STREAM_BUFFER_SIZE];

    while (size > 0) {
        int read = buffer.length;
        if (read > size) {
            read = size;/*from w w  w  .  j a  v  a  2s  .  com*/
        }
        objectStream.readFully(buffer, 0, read);

        outStream.write(buffer, 0, read);

        size -= read;
    }
}

From source file:org.mrgeo.data.raster.RasterWritable.java

private synchronized void readObject(ObjectInputStream stream) throws IOException {
    int size = stream.readInt();
    byte[] bytes = new byte[size];

    stream.readFully(bytes, 0, size);
    set(bytes, 0, size);/*ww w.  j  av  a 2s  .  c o  m*/
}