Java Code Examples for java.io.ObjectInputStream.readInt()

The following are Jave code examples for showing how to use readInt() of the java.io.ObjectInputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: Ints.java   View Source Code Vote up 6 votes
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeInt(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readInt();
        }
    }
}
 
Example 2
Project: googles-monorepo-demo   File: Serialization.java   View Source Code Vote up 6 votes
/**
 * Populates a multimap by reading an input stream, as part of
 * deserialization. See {@link #writeMultimap} for the data format. The number
 * of distinct keys is determined by a prior call to {@link #readCount}.
 */
static <K, V> void populateMultimap(
    Multimap<K, V> multimap, ObjectInputStream stream, int distinctKeys)
    throws IOException, ClassNotFoundException {
  for (int i = 0; i < distinctKeys; i++) {
    @SuppressWarnings("unchecked") // reading data stored by writeMultimap
    K key = (K) stream.readObject();
    Collection<V> values = multimap.get(key);
    int valueCount = stream.readInt();
    for (int j = 0; j < valueCount; j++) {
      @SuppressWarnings("unchecked") // reading data stored by writeMultimap
      V value = (V) stream.readObject();
      values.add(value);
    }
  }
}
 
Example 3
Project: sstore-soft   File: Serialization.java   View Source Code Vote up 6 votes
/**
 * Populates a multimap by reading an input stream, as part of
 * deserialization. See {@link #writeMultimap} for the data format. The number
 * of distinct keys is determined by a prior call to {@link #readCount}.
 */
static <K, V> void populateMultimap(
    Multimap<K, V> multimap, ObjectInputStream stream, int distinctKeys)
    throws IOException, ClassNotFoundException {
  for (int i = 0; i < distinctKeys; i++) {
    @SuppressWarnings("unchecked") // reading data stored by writeMultimap
    K key = (K) stream.readObject();
    Collection<V> values = multimap.get(key);
    int valueCount = stream.readInt();
    for (int j = 0; j < valueCount; j++) {
      @SuppressWarnings("unchecked") // reading data stored by writeMultimap
      V value = (V) stream.readObject();
      values.add(value);
    }
  }
}
 
Example 4
Project: morpheus-core   File: DenseArrayWithIntCoding.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
/** Custom serialization */
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
    this.coding = (IntCoding<T>)is.readObject();
    final int length = is.readInt();
    this.codes = new int[length];
    for (int i=0; i<length; ++i) {
        codes[i] = is.readInt();
    }
}
 
Example 5
Project: graphflow   File: Graph.java   View Source Code Vote up 5 votes
@Override
public void deserializeMainFile(ObjectInputStream objectInputStream) throws IOException,
    ClassNotFoundException {
    highestPermanentVertexId = objectInputStream.readInt();
    highestMergedVertexId = highestPermanentVertexId;
    int forwardAdjListsLength = objectInputStream.readInt();
    int backwardAdjListsLength = objectInputStream.readInt();
    forwardAdjLists = new SortedAdjacencyList[forwardAdjListsLength];
    backwardAdjLists = new SortedAdjacencyList[backwardAdjListsLength];
    initializeSortedAdjacencyLists(0, highestPermanentVertexId + 1);
    vertexTypes.deserialize(objectInputStream);
}
 
Example 6
Project: datatree   File: Tree.java   View Source Code Vote up 5 votes
/**
 * Loads (deserializes) this node's content from the source stream.
 * 
 * @param in
 *            source stream
 * 
 * @throws IOException
 *             any I/O exception
 * @throws ClassNotFoundException
 *             class not found
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
	in.defaultReadObject();
	byte[] bytes = new byte[in.readInt()];
	in.readFully(bytes);
	try {
		value = JavaBuiltin.deserialize(bytes);
	} catch (Exception e) {
		throw new IOException(e);
	}
	moveMeta();
}
 
Example 7
Project: googles-monorepo-demo   File: MapMakerInternalMap.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation") // serialization of deprecated feature
MapMaker readMapMaker(ObjectInputStream in) throws IOException {
  int size = in.readInt();
  return new MapMaker()
      .initialCapacity(size)
      .setKeyStrength(keyStrength)
      .setValueStrength(valueStrength)
      .keyEquivalence(keyEquivalence)
      .concurrencyLevel(concurrencyLevel);
}
 
Example 8
Project: Pogamut3   File: LevelGeometry.java   View Source Code Vote up 5 votes
protected void readObject(ObjectInputStream in) throws IOException {
	loaded = in.readBoolean();
	
	ArrayList<Point3D> allVertices = Lists.newArrayList();
	int vertexCount = in.readInt();
	while ( allVertices.size() < vertexCount ) {
		double x = in.readDouble();
		double y = in.readDouble();
		double z = in.readDouble(); 
		allVertices.add( new Point3D( x, y, z ) );
	}
	
	triangles = Lists.newArrayList();
	int triangleCount = in.readInt();
	while ( triangles.size() < triangleCount ) {
		Point3D triangleVertices[] = new Point3D[3];
		for ( int i=0; i<3; ++i ) {
    		triangleVertices[i] = allVertices.get( in.readInt() );
		}
		triangles.add( new Triangle( triangleVertices[0], triangleVertices[1], triangleVertices[2] ) );
	}
	
    bspTree = BspTree.make( new RayCastBspStrategy( this, new Random(250760834l) ) );
    rayCaster = new RayCaster( bspTree );
    
    bspTree.setRoot( readNode( in ) );
}
 
Example 9
Project: incubator-netbeans   File: HeapHistogramResponse.java   View Source Code Vote up 5 votes
void readObject(ObjectInputStream in) throws IOException {
    long t = in.readLong();
    time = new Date(t);
    int len = in.readInt();
    newNames = new String[len];
    for (int i = 0; i < len; i++) {
        newNames[i] = in.readUTF();
    }
    len = in.readInt();
    newids = new int[len];
    for (int i = 0; i < len; i++) {
        newids[i] = in.readInt();
    }
    len = in.readInt();
    ids = new int[len];
    for (int i = 0; i < len; i++) {
        ids[i] = in.readInt();
    }
    len = in.readInt();
    instances = new long[len];
    for (int i = 0; i < len; i++) {
        instances[i] = in.readLong();
    }
    len = in.readInt();
    bytes = new long[len];
    for (int i = 0; i < len; i++) {
        bytes[i] = in.readLong();
    }
}
 
Example 10
Project: guava-mock   File: Serialization.java   View Source Code Vote up 5 votes
/**
 * Populates a multiset by reading an input stream, as part of
 * deserialization. See {@link #writeMultiset} for the data format. The number
 * of distinct elements is determined by a prior call to {@link #readCount}.
 */
static <E> void populateMultiset(
    Multiset<E> multiset, ObjectInputStream stream, int distinctElements)
    throws IOException, ClassNotFoundException {
  for (int i = 0; i < distinctElements; i++) {
    @SuppressWarnings("unchecked") // reading data stored by writeMultiset
    E element = (E) stream.readObject();
    int count = stream.readInt();
    multiset.add(element, count);
  }
}
 
Example 11
Project: effectiveJava   File: StringList.java   View Source Code Vote up 5 votes
private void readObject(ObjectInputStream s) throws IOException,
		ClassNotFoundException{
	s.defaultReadObject();
	int numElements = s.readInt();
	
	//Read in all elements and insert them in list
	for (int i = 0; i < numElements; i++) {
		add((String) s.readObject());
	}
}
 
Example 12
Project: effectiveJava   File: Foo.java   View Source Code Vote up 5 votes
private void readObject(ObjectInputStream s) throws IOException,
		ClassNotFoundException {
	s.defaultReadObject();
	
	// Manually deserialize and initialize superclass state
	//�ֶ������л��ͳ�ʼ������״̬
	int x = s.readInt();
	int y = s.readInt();
	initialize(x, y);
}
 
Example 13
Project: morpheus-core   File: SparseArrayWithIntCoding.java   View Source Code Vote up 5 votes
@Override
public final void read(ObjectInputStream is, int count) throws IOException {
    for (int i=0; i<count; ++i) {
        final int value = is.readInt();
        this.codes.put(i, value);
    }
}
 
Example 14
Project: guava-mock   File: ImmutableSetMultimap.java   View Source Code Vote up 4 votes
@GwtIncompatible // java.io.ObjectInputStream
// Serialization type safety is at the caller's mercy.
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  Comparator<Object> valueComparator = (Comparator<Object>) stream.readObject();
  int keyCount = stream.readInt();
  if (keyCount < 0) {
    throw new InvalidObjectException("Invalid key count " + keyCount);
  }
  ImmutableMap.Builder<Object, ImmutableSet<Object>> builder = ImmutableMap.builder();
  int tmpSize = 0;

  for (int i = 0; i < keyCount; i++) {
    Object key = stream.readObject();
    int valueCount = stream.readInt();
    if (valueCount <= 0) {
      throw new InvalidObjectException("Invalid value count " + valueCount);
    }

    ImmutableSet.Builder<Object> valuesBuilder = valuesBuilder(valueComparator);
    for (int j = 0; j < valueCount; j++) {
      valuesBuilder.add(stream.readObject());
    }
    ImmutableSet<Object> valueSet = valuesBuilder.build();
    if (valueSet.size() != valueCount) {
      throw new InvalidObjectException("Duplicate key-value pairs exist for key " + key);
    }
    builder.put(key, valueSet);
    tmpSize += valueCount;
  }

  ImmutableMap<Object, ImmutableSet<Object>> tmpMap;
  try {
    tmpMap = builder.build();
  } catch (IllegalArgumentException e) {
    throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
  }

  FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
  FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
  FieldSettersHolder.EMPTY_SET_FIELD_SETTER.set(this, emptySet(valueComparator));
}
 
Example 15
Project: guava-mock   File: Serialization.java   View Source Code Vote up 4 votes
/**
 * Populates a map by reading an input stream, as part of deserialization.
 * See {@link #writeMap} for the data format.
 */
static <K, V> void populateMap(Map<K, V> map, ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
  int size = stream.readInt();
  populateMap(map, stream, size);
}
 
Example 16
Project: sstore-soft   File: ImmutableSetMultimap.java   View Source Code Vote up 4 votes
@GwtIncompatible("java.io.ObjectInputStream")
// Serialization type safety is at the caller's mercy.
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  Comparator<Object> valueComparator =
      (Comparator<Object>) stream.readObject();
  int keyCount = stream.readInt();
  if (keyCount < 0) {
    throw new InvalidObjectException("Invalid key count " + keyCount);
  }
  ImmutableMap.Builder<Object, ImmutableSet<Object>> builder
      = ImmutableMap.builder();
  int tmpSize = 0;

  for (int i = 0; i < keyCount; i++) {
    Object key = stream.readObject();
    int valueCount = stream.readInt();
    if (valueCount <= 0) {
      throw new InvalidObjectException("Invalid value count " + valueCount);
    }

    Object[] array = new Object[valueCount];
    for (int j = 0; j < valueCount; j++) {
      array[j] = stream.readObject();
    }
    ImmutableSet<Object> valueSet = valueSet(valueComparator, asList(array));
    if (valueSet.size() != array.length) {
      throw new InvalidObjectException(
          "Duplicate key-value pairs exist for key " + key);
    }
    builder.put(key, valueSet);
    tmpSize += valueCount;
  }

  ImmutableMap<Object, ImmutableSet<Object>> tmpMap;
  try {
    tmpMap = builder.build();
  } catch (IllegalArgumentException e) {
    throw (InvalidObjectException)
        new InvalidObjectException(e.getMessage()).initCause(e);
  }

  FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
  FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
  FieldSettersHolder.EMPTY_SET_FIELD_SETTER.set(
      this, emptySet(valueComparator));
}
 
Example 17
Project: APacheSynapseSimplePOC   File: JRMPListener.java   View Source Code Vote up 4 votes
private void doCall ( DataInputStream in, DataOutputStream out, Object payload ) throws Exception {
    ObjectInputStream ois = new ObjectInputStream(in) {

        @Override
        protected Class<?> resolveClass ( ObjectStreamClass desc ) throws IOException, ClassNotFoundException {
            if ( "[Ljava.rmi.server.ObjID;".equals(desc.getName())) {
                return ObjID[].class;
            } else if ("java.rmi.server.ObjID".equals(desc.getName())) {
                return ObjID.class;
            } else if ( "java.rmi.server.UID".equals(desc.getName())) {
                return UID.class;
            }
            throw new IOException("Not allowed to read object");
        }
    };

    ObjID read;
    try {
        read = ObjID.read(ois);
    }
    catch ( java.io.IOException e ) {
        throw new MarshalException("unable to read objID", e);
    }


    if ( read.hashCode() == 2 ) {
        ois.readInt(); // method
        ois.readLong(); // hash
        System.err.println("Is DGC call for " + Arrays.toString((ObjID[])ois.readObject()));
    }

    System.err.println("Sending return with payload for obj " + read);

    out.writeByte(TransportConstants.Return);// transport op
    ObjectOutputStream oos = new JRMPClient.MarshalOutputStream(out, this.classpathUrl);

    oos.writeByte(TransportConstants.ExceptionalReturn);
    new UID().write(oos);

    BadAttributeValueExpException ex = new BadAttributeValueExpException(null);
    Reflections.setFieldValue(ex, "val", payload);
    oos.writeObject(ex);

    oos.flush();
    out.flush();

    this.hadConnection = true;
    synchronized ( this.waitLock ) {
        this.waitLock.notifyAll();
    }
}
 
Example 18
Project: Android_Code_Arbiter   File: SerialisationFalsePositive.java   View Source Code Vote up 4 votes
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
    param1 = inputStream.readInt();
    param2 = inputStream.readObject();
}
 
Example 19
Project: guava-mock   File: Serialization.java   View Source Code Vote up 2 votes
/**
 * Reads a count corresponding to a serialized map, multiset, or multimap. It
 * returns the size of a map serialized by {@link
 * #writeMap(Map, ObjectOutputStream)}, the number of distinct elements in a
 * multiset serialized by {@link
 * #writeMultiset(Multiset, ObjectOutputStream)}, or the number of distinct
 * keys in a multimap serialized by {@link
 * #writeMultimap(Multimap, ObjectOutputStream)}.
 */
static int readCount(ObjectInputStream stream) throws IOException {
  return stream.readInt();
}
 
Example 20
Project: sstore-soft   File: Serialization.java   View Source Code Vote up 2 votes
/**
 * Reads a count corresponding to a serialized map, multiset, or multimap. It
 * returns the size of a map serialized by {@link
 * #writeMap(Map, ObjectOutputStream)}, the number of distinct elements in a
 * multiset serialized by {@link
 * #writeMultiset(Multiset, ObjectOutputStream)}, or the number of distinct
 * keys in a multimap serialized by {@link
 * #writeMultimap(Multimap, ObjectOutputStream)}.
 *
 * <p>The returned count may be used to construct an empty collection of the
 * appropriate capacity before calling any of the {@code populate} methods.
 */
static int readCount(ObjectInputStream stream) throws IOException {
  return stream.readInt();
}