Java Code Examples for java.io.ObjectInput#read()

The following examples show how to use java.io.ObjectInput#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadableByteArrayInputStream.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void readFromStream(ObjectInput in, int size) throws IOException
{
    if (size > buf.length)
    {
        buf = new byte[size];
    }
    int read = 0;
    while (read < size)
    {
        int moreRead = in.read(buf, read, size - read);
        if (moreRead < 0) throw new IOException("Could not read "+size+" bytes from stream");
        read += moreRead;
    }
    this.count = size;
    this.pos = 0;
}
 
Example 2
Source File: BroadcastNotification.java    From riotapi with Apache License 2.0 5 votes vote down vote up
public void readExternal(ObjectInput in) throws IOException {
    byte[] buffer = new byte[in.readInt()];
    int i = 0;
    while (i < buffer.length - 1) {
        i += in.read(buffer, i, buffer.length - i);
    }
    String json = new String(buffer, "UTF-8");
    JsonElement elem = new JsonParser().parse(json);
    this.json = elem == null || elem.isJsonNull() ? null : elem.getAsJsonObject();
}
 
Example 3
Source File: AbstractStruct.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
	int len = in.readInt();
	byte[] storage = new byte[len];
	in.read(storage);
	setByteBuffer(ByteBuffer.wrap(storage).order(ByteOrder.LITTLE_ENDIAN), 0);
}
 
Example 4
Source File: GridMarshallerAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    fully = in.readBoolean();

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

    if (fully)
        in.readFully(arr);
    else
        in.read(arr);
}
 
Example 5
Source File: EJBMetaDataImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
    final byte version = in.readByte(); // future use

    homeClass = (Class) in.readObject();
    remoteClass = (Class) in.readObject();
    keyClass = (Class) in.readObject();
    ejbHomeProxy = (EJBHome) in.readObject();
    type = in.readByte();
    deploymentID = in.readUTF();
    deploymentCode = in.readShort();

    for (int i = in.readShort(); i > 0; i--) {
        businessClasses.add((Class) in.readObject());
    }
    if (businessClasses.size() > 0) {
        primaryKey = in.readObject();
    }
    if (version > 2) {
        mainInterface = (Class) in.readObject();
    }
    if (version > 1) {
        final byte typeIndex = in.readByte();
        interfaceType = InterfaceType.values()[typeIndex];
    }
    for (int i = in.readInt(); i > 0; i--) {
        asynchronousMethods.add((String) in.readObject());
    }

    final boolean hasProperties = in.readBoolean();
    if (hasProperties) {
        final int bufferLength = in.readInt();
        final byte[] buffer = new byte[bufferLength];
        in.read(buffer);
        final ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        properties.load(bais);
    }
}
 
Example 6
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Read the base state of the instance.
 * This method does <strong>neither</strong> set the interpolated
 * time nor state. It is up to the derived class to reset it
 * properly calling the {@link #setInterpolatedTime} method later,
 * once all rest of the object state has been set up properly.
 * @param in stream where to read the state from
 * @return interpolated time to be set later by the caller
 * @exception IOException in case of read error
 * @exception ClassNotFoundException if an equation mapper class
 * cannot be found
 */
protected double readBaseExternal(final ObjectInput in)
  throws IOException, ClassNotFoundException {

  final int dimension = in.readInt();
  globalPreviousTime  = in.readDouble();
  globalCurrentTime   = in.readDouble();
  softPreviousTime    = in.readDouble();
  softCurrentTime     = in.readDouble();
  h                   = in.readDouble();
  forward             = in.readBoolean();
  primaryMapper       = (EquationsMapper) in.readObject();
  secondaryMappers    = new EquationsMapper[in.read()];
  for (int i = 0; i < secondaryMappers.length; ++i) {
      secondaryMappers[i] = (EquationsMapper) in.readObject();
  }
  dirtyState          = true;

  if (dimension < 0) {
      currentState = null;
  } else {
      currentState  = new double[dimension];
      for (int i = 0; i < currentState.length; ++i) {
          currentState[i] = in.readDouble();
      }
  }

  // we do NOT handle the interpolated time and state here
  interpolatedTime = Double.NaN;
  allocateInterpolatedArrays(dimension);

  finalized = true;

  return in.readDouble();

}
 
Example 7
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Read the base state of the instance.
 * This method does <strong>neither</strong> set the interpolated
 * time nor state. It is up to the derived class to reset it
 * properly calling the {@link #setInterpolatedTime} method later,
 * once all rest of the object state has been set up properly.
 * @param in stream where to read the state from
 * @return interpolated time to be set later by the caller
 * @exception IOException in case of read error
 * @exception ClassNotFoundException if an equation mapper class
 * cannot be found
 */
protected double readBaseExternal(final ObjectInput in)
  throws IOException, ClassNotFoundException {

  final int dimension = in.readInt();
  globalPreviousTime  = in.readDouble();
  globalCurrentTime   = in.readDouble();
  softPreviousTime    = in.readDouble();
  softCurrentTime     = in.readDouble();
  h                   = in.readDouble();
  forward             = in.readBoolean();
  primaryMapper       = (EquationsMapper) in.readObject();
  secondaryMappers    = new EquationsMapper[in.read()];
  for (int i = 0; i < secondaryMappers.length; ++i) {
      secondaryMappers[i] = (EquationsMapper) in.readObject();
  }
  dirtyState          = true;

  if (dimension < 0) {
      currentState = null;
  } else {
      currentState  = new double[dimension];
      for (int i = 0; i < currentState.length; ++i) {
          currentState[i] = in.readDouble();
      }
  }

  // we do NOT handle the interpolated time and state here
  interpolatedTime = Double.NaN;
  allocateInterpolatedArrays(dimension);

  finalized = true;

  return in.readDouble();

}
 
Example 8
Source File: StoredFieldHeader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
	read the field status

	@exception IOException Thrown by potential I/O errors while reading 
                              field header.
 */
public static final int readStatus(ObjectInput in) 
       throws IOException 
   {
	int status;

	if ((status = in.read()) >= 0)
           return status;
       else
		throw new EOFException();
}
 
Example 9
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Read the base state of the instance.
 * This method does <strong>neither</strong> set the interpolated
 * time nor state. It is up to the derived class to reset it
 * properly calling the {@link #setInterpolatedTime} method later,
 * once all rest of the object state has been set up properly.
 * @param in stream where to read the state from
 * @return interpolated time to be set later by the caller
 * @exception IOException in case of read error
 * @exception ClassNotFoundException if an equation mapper class
 * cannot be found
 */
protected double readBaseExternal(final ObjectInput in)
  throws IOException, ClassNotFoundException {

  final int dimension = in.readInt();
  globalPreviousTime  = in.readDouble();
  globalCurrentTime   = in.readDouble();
  softPreviousTime    = in.readDouble();
  softCurrentTime     = in.readDouble();
  h                   = in.readDouble();
  forward             = in.readBoolean();
  primaryMapper       = (EquationsMapper) in.readObject();
  secondaryMappers    = new EquationsMapper[in.read()];
  for (int i = 0; i < secondaryMappers.length; ++i) {
      secondaryMappers[i] = (EquationsMapper) in.readObject();
  }
  dirtyState          = true;

  if (dimension < 0) {
      currentState = null;
  } else {
      currentState  = new double[dimension];
      for (int i = 0; i < currentState.length; ++i) {
          currentState[i] = in.readDouble();
      }
  }

  // we do NOT handle the interpolated time and state here
  interpolatedTime = Double.NaN;
  allocateInterpolatedArrays(dimension);

  finalized = true;

  return in.readDouble();

}
 
Example 10
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Read the base state of the instance.
 * This method does <strong>neither</strong> set the interpolated
 * time nor state. It is up to the derived class to reset it
 * properly calling the {@link #setInterpolatedTime} method later,
 * once all rest of the object state has been set up properly.
 * @param in stream where to read the state from
 * @return interpolated time to be set later by the caller
 * @exception IOException in case of read error
 * @exception ClassNotFoundException if an equation mapper class
 * cannot be found
 */
protected double readBaseExternal(final ObjectInput in)
  throws IOException, ClassNotFoundException {

  final int dimension = in.readInt();
  globalPreviousTime  = in.readDouble();
  globalCurrentTime   = in.readDouble();
  softPreviousTime    = in.readDouble();
  softCurrentTime     = in.readDouble();
  h                   = in.readDouble();
  forward             = in.readBoolean();
  primaryMapper       = (EquationsMapper) in.readObject();
  secondaryMappers    = new EquationsMapper[in.read()];
  for (int i = 0; i < secondaryMappers.length; ++i) {
      secondaryMappers[i] = (EquationsMapper) in.readObject();
  }
  dirtyState          = true;

  if (dimension < 0) {
      currentState = null;
  } else {
      currentState  = new double[dimension];
      for (int i = 0; i < currentState.length; ++i) {
          currentState[i] = in.readDouble();
      }
  }

  // we do NOT handle the interpolated time and state here
  interpolatedTime = Double.NaN;
  allocateInterpolatedArrays(dimension);

  finalized = true;

  return in.readDouble();

}
 
Example 11
Source File: NoteCoordinate.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(final ObjectInput arg0) throws IOException, ClassNotFoundException {
	byte[] bytes = extreadbuffer_.get();
	arg0.read(bytes);
	this.db = Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]);
	this.x = Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]);
	this.y = Longs.fromBytes(bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23]);
}
 
Example 12
Source File: NoteSet.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(final ObjectInput arg0) throws IOException, ClassNotFoundException {
	int size = arg0.readInt();
	byte[] buffer = new byte[24];
	for (int i = 0; i < size; i++) {
		arg0.read(buffer);
		add(new NoteCoordinate(buffer));
	}
}
 
Example 13
Source File: RemoteMethodCallResults.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
  final boolean hasReturnValue = in.read() == 1;
  if (hasReturnValue) {
    returnValue = in.readObject();
  } else {
    exception = (Throwable) in.readObject();
  }
}
 
Example 14
Source File: BigDecimalAttribute.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public BigDecimal readFromStream(ObjectInput in) throws IOException
{
    int length = in.readInt();
    byte[] buf = new byte[length];
    int read = in.read(buf);
    while(read < length)
    {
        read += in.read(buf, read, length - read);
    }
    BigInteger unscaledValue = new BigInteger(buf);
    return  new BigDecimal(unscaledValue, in.readInt());
}
 
Example 15
Source File: MeasureUnit.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    /* byte version = */ in.readByte(); // version
    type = in.readUTF();
    subType = in.readUTF();
    // allow for more data from future version
    int extra = in.readShort();
    if (extra > 0) {
        byte[] extraBytes = new byte[extra];
        in.read(extraBytes, 0, extra);
    }
}
 
Example 16
Source File: StoredFieldHeader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
	read the field data length

	@exception IOException Thrown by potential I/O errors while reading 
                              field header.
 */
public static final int readFieldDataLength(
   ObjectInput in, 
   int status, 
   int fieldDataSize)
		throws IOException 
   {
	
       if ((status & (FIELD_NULL | FIELD_FIXED)) == 0)
       {
           // usual case-not null, not fixed.  Length stored as compressed int.
           return(CompressedNumber.readInt(in));
       }
       else if ((status & FIELD_NULL) != 0)
       {
           // field is null or non-existent.
           return(0);
       }
       else
       {
           int fieldDataLength;

           // field data length is in a fixed size field, not compressed.

           if (fieldDataSize <= 2)
           {
               // read it in as short, because it was written out as short
               int ch1 = in.read();
               int ch2 = in.read();
               if ((ch1 | ch2) < 0)
                    throw new EOFException();

               fieldDataLength = ((ch1 << 8) + (ch2 << 0));
           }
           else
           {
               fieldDataLength = 
                   CompressedNumber.readInt(in);

               int diffLen = 
                   fieldDataSize - 
                   CompressedNumber.sizeInt(fieldDataLength);

               if (diffLen != 0)
                   in.skipBytes(diffLen);
           } 

           return(fieldDataLength);
       }
}
 
Example 17
Source File: CDPATTERNTABLE.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
	int length = in.readInt();
	data_ = new byte[length];
	in.read(data_);
}
 
Example 18
Source File: FakeByteArray.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void readExternal( ObjectInput in ) throws IOException
{
    _length = in.readInt();

    for ( int i = 0; i < _length; i++ ) { _fill = (byte) in.read(); }
}
 
Example 19
Source File: SQLBinary.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Read the encoded length of the value from the on-disk format.
 * 
 * @see SQLBinary
*/
private static int readBinaryLength(ObjectInput in) throws IOException {

    int bl = in.read();
    if (bl == -1)
        throw new java.io.EOFException();
    
    byte li = (byte) bl;

    int len;
    if ((li & ((byte) 0x80)) != 0)
    {
        if (li == ((byte) 0xC0))
        {
            len = in.readInt();
         }
        else if (li == ((byte) 0xA0))
        {
            len = in.readUnsignedShort();
        }
        else
        {
            len = li & 0x1F;
        }
    }
    else
    {
        
        // old length in bits
        int v2 = in.read();
        int v3 = in.read();
        int v4 = in.read();
        if (v2 == -1 || v3 == -1 || v4 == -1)
            throw new java.io.EOFException();
        int lenInBits = (((bl & 0xff) << 24) | ((v2 & 0xff) << 16) | ((v3 & 0xff) << 8) | (v4 & 0xff));

        len = lenInBits / 8;
        if ((lenInBits % 8) != 0)
            len++;
     }
    return len;
}
 
Example 20
Source File: ConsensusMessage.java    From protect with MIT License 3 votes vote down vote up
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

	super.readExternal(in);

	number = in.readInt();
	epoch = in.readInt();
	paxosType = PaxosMessageType.getPaxosMessageByValue(in.readInt());

	int toRead = in.readInt();

	if (toRead != -1) {

		value = new byte[toRead];

		do {

			toRead -= in.read(value, value.length - toRead, toRead);

		} while (toRead > 0);

	}

	boolean asProof = in.readBoolean();
	if (asProof) {

		proof = in.readObject();
	}

}