Java Code Examples for java.io.ObjectOutputStream#writeShort()

The following examples show how to use java.io.ObjectOutputStream#writeShort() . These examples are extracted from open source projects. 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
/**
 * 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.writeShort(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readShort();
        }
    }
}
 
Example 2
Source Project: jdk8u_jdk   File: Shorts.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.writeShort(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readShort();
        }
    }
}
 
Example 3
Source Project: jdk8u60   File: Shorts.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.writeShort(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readShort();
        }
    }
}
 
Example 4
/**
 * Writes an array of parameter types to the stream.
 *
 * Requires special handling because primitive types cannot be
 * found upon deserialization by the default Java implementation.
 */
private static void writeParameters(ObjectOutputStream out, Class<?>[] parms)
    throws IOException
{
    out.writeShort(parms.length);
outer:
    for (int i=0; i < parms.length; i++) {
        Class<?> parm = parms[i];
        boolean primitive = parm.isPrimitive();
        out.writeBoolean(primitive);
        if (!primitive) {
            out.writeObject(parm);
            continue;
        }
        for (int j=0; j < primitives.length; j++) {
            if (parm.equals(primitives[j])) {
                out.writeByte(j);
                continue outer;
            }
        }
        throw new IllegalArgumentException("Primitive " + parm +
                                           " not found");
    }
}
 
Example 5
/**
 * 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.writeShort(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readShort();
        }
    }
}
 
Example 6
Source Project: hottub   File: Shorts.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.writeShort(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readShort();
        }
    }
}
 
Example 7
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 8
Source Project: geowave   File: RasterTileResizeHelper.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(final ObjectOutputStream aOutputStream) throws IOException {
  final byte[] adapterBytes = PersistenceUtils.toBinary(newAdapter);
  final byte[] indexBytes = PersistenceUtils.toBinary(index);
  aOutputStream.writeShort(adapterBytes.length);
  aOutputStream.write(adapterBytes);
  aOutputStream.writeShort(indexBytes.length);
  aOutputStream.write(indexBytes);
  aOutputStream.writeShort(oldAdapterId);
  aOutputStream.writeShort(newAdapterId);
  aOutputStream.flush();
}
 
Example 9
Source Project: mars-sim   File: StarRater.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an image to a compressed byte array. GZIPs the image to reduce the size. Use compressedByteArrayToImage(byte[] data) to
 * retrieve the original image. The image is not recognizable as image from standard tools.
 *
 * @param image  The image to convert.
 * @return  The byte array.
 * @throws IOException if something goes wrong.
 */
public byte[] imageToCompressedByteArray(Image image) throws IOException {
  // get image size
  int width = image.getWidth(null);
  int height = image.getHeight(null);

  // store image data as raw int values
  try {
    int[] imageSource = new int[width * height];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, imageSource, 0, width);
    pg.grabPixels();

    // zip data
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    GZIPOutputStream zippedStream = new GZIPOutputStream(byteStream);
    ObjectOutputStream objectStream = new ObjectOutputStream(zippedStream);
    objectStream.writeShort(width);
    objectStream.writeShort(height);
    objectStream.writeObject(imageSource);
    objectStream.flush();
    objectStream.close();
    return byteStream.toByteArray();
  }
  catch (Exception e) {
    throw new IOException("Error storing image in object: " + e);
  }
}
 
Example 10
Source Project: super-cloudops   File: IamSession.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serializes this object to the specified output stream for JDK
 * Serialization.
 *
 * @param out
 *            output stream used for Object serialization.
 * @throws IOException
 *             if any of this object's fields cannot be written to the
 *             stream.
 * @since 1.0
 */
@JsonIgnore
private void writeObject(ObjectOutputStream out) throws IOException {
	out.defaultWriteObject();
	short alteredFieldsBitMask = getAlteredFieldsBitMask();
	out.writeShort(alteredFieldsBitMask);
	if (id != null) {
		out.writeObject(id);
	}
	if (startTimestamp != null) {
		out.writeObject(startTimestamp);
	}
	if (stopTimestamp != null) {
		out.writeObject(stopTimestamp);
	}
	if (lastAccessTime != null) {
		out.writeObject(lastAccessTime);
	}
	if (timeout != 0l) {
		out.writeLong(timeout);
	}
	if (expired) {
		out.writeBoolean(expired);
	}
	if (host != null) {
		out.writeUTF(host);
	}
	if (!CollectionUtils.isEmpty(attributes)) {
		out.writeObject(attributes);
	}
}
 
Example 11
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 12
Source Project: tcl-regex-java   File: RuntimeColorMap.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(ObjectOutputStream stream) throws IOException {
    // TreeRangeMap is not Serializable.
    Set<Map.Entry<Range<Integer>, Short>> entries = fullMap.asMapOfRanges().entrySet();
    stream.writeInt(entries.size());
    for (Map.Entry<Range<Integer>, Short> me : entries) {
        stream.writeObject(me.getKey());
        stream.writeShort(me.getValue());
    }
}
 
Example 13
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 14
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 15
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 16
@Override
public final void write(ObjectOutputStream os, int[] indexes) throws IOException {
    for (int index : indexes) {
        final long value = getLong(index);
        os.writeLong(value);
        if (value != defaultValueAsLong) {
            final short zoneId = zoneIds.get(index);
            os.writeShort(zoneId);
        }
    }
}
 
Example 17
@Override
public final void write(ObjectOutputStream os, int[] indexes) throws IOException {
    for (int index : indexes) {
        final int byteIndex = index * BYTE_COUNT;
        final long epochMillis = byteBuffer.getLong(byteIndex);
        final short zoneId = byteBuffer.getShort(byteIndex + 8);
        os.writeLong(epochMillis);
        os.writeShort(zoneId);
    }
}
 
Example 18
/** Custom serialization */
private void writeObject(ObjectOutputStream os) throws IOException {
    os.writeInt(length);
    os.writeLong(defaultValueAsLong);
    os.writeShort(defaultZoneId);
    os.writeObject(defaultValue);
    for (int i=0; i<length; ++i) {
        final int byteIndex = i * BYTE_COUNT;
        final long epochMillis = byteBuffer.getLong(byteIndex);
        final short zoneId = byteBuffer.getShort(byteIndex + 8);
        os.writeLong(epochMillis);
        os.writeShort(zoneId);
    }
}
 
Example 19
@Override
public final void write(ObjectOutputStream os, int[] indexes) throws IOException {
    for (int index : indexes) {
        final long value = values[index];
        os.writeLong(value);
        if (value != defaultValueAsLong) {
            os.writeShort(zoneIds[index]);
        }
    }
}
 
Example 20
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}