Example usage for java.io ObjectInputStream readInt

List of usage examples for java.io ObjectInputStream readInt

Introduction

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

Prototype

public int readInt() throws IOException 

Source Link

Document

Reads a 32 bit int.

Usage

From source file:com.lillicoder.newsblurry.net.SerializableCookie.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    // Read all values from write operation in order.
    String comment = (String) in.readObject();
    String domain = (String) in.readObject();
    Date expiryDate = (Date) in.readObject();
    String name = (String) in.readObject();
    String path = (String) in.readObject();
    String value = (String) in.readObject();
    int version = in.readInt();
    boolean isSecure = in.readBoolean();

    // Create a new basic cookie and set this wrapper's cookie instance.
    BasicClientCookie cookie = new BasicClientCookie(name, value);
    cookie.setComment(comment);//from   w w  w. j a  va  2s.  co m
    cookie.setDomain(domain);
    cookie.setExpiryDate(expiryDate);
    cookie.setPath(path);
    cookie.setValue(value);
    cookie.setVersion(version);
    cookie.setSecure(isSecure);

    this.setCookie(cookie);
}

From source file:org.jactr.tools.async.message.ast.BaseASTMessage.java

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();/*  w ww .ja  v  a 2s .  c o m*/
    boolean astIsNotNull = in.readBoolean();
    if (astIsNotNull) {
        boolean wasCompressed = in.readBoolean();

        if (wasCompressed) {
            /*
             * pull through GZIPInputStream. this can be done more effeciently..
             */
            int len = in.readInt();

            byte[] bytes = _localInput.get();
            if (bytes == null || bytes.length < len) {
                bytes = new byte[len];
                _localInput.set(bytes);
            }

            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Reading " + len + " bytes to decompress");

            in.read(bytes, 0, len);

            // in.readFully(bytes);

            ByteArrayInputStream bais = new ByteArrayInputStream(bytes, 0, len);
            DataInputStream zip = new DataInputStream(new GZIPInputStream(bais));
            _ast = Serializer.read(zip);
        } else
            _ast = Serializer.read(in);
    }
}

From source file:ddf.catalog.data.impl.MetacardTypeImpl.java

/**
 * Deserializes this {@link MetacardTypeImpl} instance.
 *
 * @param stream the {@link ObjectInputStream} that contains the bytes of the object
 * @throws IOException//from   w w  w.  ja  v  a  2 s  .  c o m
 * @throws ClassNotFoundException
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {

    /*
     * defaultReadObject() is invoked for greater flexibility and compatibility. See the
     * *Serialization Note* in MetacardImpl's class Javadoc.
     */
    stream.defaultReadObject();

    int numElements = stream.readInt();

    descriptors = new HashMap<>();

    for (int i = 0; i < numElements; i++) {
        AttributeDescriptor descriptor = (AttributeDescriptor) stream.readObject();
        descriptors.put(descriptor.getName(), descriptor);
    }
}

From source file:org.largecollections.CacheSet.java

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    this.folder = (String) in.readObject();
    this.name = (String) in.readObject();
    this.cacheSize = in.readInt();
    this.size = in.readInt();
    Map m = DBUtils.createDB(this.folder, this.name, this.cacheSize);
    this.db = (DB) m.get(Constants.DB_KEY);
    this.options = (Options) m.get(Constants.DB_OPTIONS_KEY);
    this.dbFile = (File) m.get(Constants.DB_FILE_KEY);
}

From source file:com.ab.http.SerializableCookie.java

/**
 * Read object.//  w w w . j  a v a 2  s. co  m
 *
 * @param in the in
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws ClassNotFoundException the class not found exception
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}

From source file:org.protempa.backend.dsb.relationaldb.SQLGenLocalUniqueId.java

private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    this.entitySpecName = (String) s.readObject();
    if (this.entitySpecName == null) {
        throw new InvalidObjectException("name cannot be null. Can't restore");
    }//from w w  w. j  a v  a  2  s.  c om

    // We intern entity spec names elsewhere, so let's do it here too.
    this.entitySpecName = this.entitySpecName.intern();

    int dbIdsLen = s.readInt();
    if (dbIdsLen < 0) {
        throw new InvalidObjectException("dbIds length invalid (" + dbIdsLen + "). Can't restore");
    }
    this.dbIds = new String[dbIdsLen];
    for (int i = 0; i < dbIdsLen; i++) {
        String dbId = (String) s.readObject();
        if (dbId == null) {
            throw new InvalidObjectException("dbIds cannot contain a null value. Can't restore");
        }
        this.dbIds[i] = dbId;
    }
}

From source file:net.vleu.par.android.rpc.SerializableCookie.java

private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    final String name = (String) in.readObject();
    final String value = (String) in.readObject();
    this.clientCookie = new BasicClientCookie(name, value);
    this.clientCookie.setComment((String) in.readObject());
    this.clientCookie.setDomain((String) in.readObject());
    this.clientCookie.setExpiryDate((Date) in.readObject());
    this.clientCookie.setPath((String) in.readObject());
    this.clientCookie.setVersion(in.readInt());
    this.clientCookie.setSecure(in.readBoolean());
}

From source file:org.photovault.replication.ChangeDTO.java

/**
 Deserialize the change from a stream//from w w w .  jav  a 2 s . c o  m
         
 @param is
 @throws java.io.IOException
 @throws java.lang.ClassNotFoundException
 @throws IllegalStateException If the uuid of the read change does not match 
 change state.
 */
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
    is.defaultReadObject();
    changeUuid = (UUID) is.readObject();
    historyClass = (Class) is.readObject();
    targetClassName = (String) is.readObject();
    targetUuid = (UUID) is.readObject();
    int parentCount = is.readInt();
    parentIds = new ArrayList<UUID>(parentCount);
    for (int n = 0; n < parentCount; n++) {
        parentIds.add((UUID) is.readObject());
    }
    int changedFieldCount = is.readInt();
    changedFields = new TreeMap();
    for (int n = 0; n < changedFieldCount; n++) {
        FieldChange val = (FieldChange) is.readObject();
        changedFields.put((String) val.getName(), val);
    }
    verify();
}

From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpackerTest.java

/**
 * Verifies that there are multiple volumes of the expected size.
 *
 * @param dir                the directory to find the volumes in
 * @param resources          the resources used to determine the volume name and count
 * @param maxFirstVolumeSize the maximum size of the first volume
 * @param maxVolumeSize      the maximum volume size for subsequent volumes
 * @throws IOException for any I/O error
 *///  w  w w .  j  ava  2s .  co  m
private void checkVolumes(File dir, Resources resources, long maxFirstVolumeSize, long maxVolumeSize)
        throws IOException {
    // get the volume information
    ObjectInputStream info = new ObjectInputStream(resources.getInputStream(MultiVolumeUnpacker.VOLUMES_INFO));
    int count = info.readInt();
    String name = info.readUTF();
    info.close();
    assertTrue(count >= 1);

    // verify the primary volume exists, with the expected size
    File volume = new File(dir, name);
    assertTrue(volume.exists());
    assertEquals(maxFirstVolumeSize, volume.length());

    // check the existence and size of the remaining volumes
    for (int i = 1; i < count; ++i) {
        volume = new File(dir, name + "." + i);
        assertTrue(volume.exists());
        if (i < count - 1) {
            // can't check the size of the last volume
            assertEquals(maxVolumeSize, volume.length());
        }
    }
}

From source file:com.healthmarketscience.rmiio.DirectRemoteInputStream.java

/**
 * Reads the state of this object and all of the underlying stream's data
 * directly from the given ObjectInputStream. The stream data is stored in
 * a temporary file in the default java temp directory with the name {@code "stream_<num>.dat"}.
 *//*  w ww  . j  a  v  a 2s  .co m*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();

    // read the default chunk size from the incoming file
    final int defaultChunkSize = in.readInt();
    checkChunkSize(defaultChunkSize);

    // setup a temp file for the incoming data (make sure it gets cleaned up
    // somehow)
    _tmpFile = File.createTempFile("stream_", ".dat");
    _tmpFile.deleteOnExit();

    FileOutputStream out = new FileOutputStream(_tmpFile);
    try {
        // limit buffer size in case of malicious input
        byte[] transferBuf = new byte[Math.min(defaultChunkSize, RemoteInputStreamServer.DEFAULT_CHUNK_SIZE)];
        while (true) {

            // read in another chunk
            int chunkCode = in.read();
            if (chunkCode == EOF_CODE) {
                // all done
                break;
            }

            int readLen = defaultChunkSize;
            if (chunkCode != DEFAULT_CHUNK_CODE) {
                readLen = in.readInt();
                checkChunkSize(readLen);
            }

            // copy chunk into temp file
            copy(in, out, transferBuf, readLen);

        }

        // attempt to close the temp file. if successful, we're good to go
        out.close();

        // sweet, setup final state
        _monitor = RemoteInputStreamServer.DUMMY_MONITOR;
        _in = new BufferedInputStream(new FileInputStream(_tmpFile));

        // the underlying stream is now in it's initial state
        _consumptionState = ConsumptionState.NONE;
        _gotEOF = false;

    } finally {
        RmiioUtil.closeQuietly(out);
    }

}