java.io.ObjectOutputStream#writeByte ( )源码实例Demo

下面列出了java.io.ObjectOutputStream#writeByte ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sofa-registry   文件: ServerDataBox.java
private void writeObject(ObjectOutputStream out) throws IOException {
    if (isInBytes()) {
        out.writeByte(serialization); // Write serialization type
        out.writeInt(bytes.length); // Write byte stream size
        out.write(bytes); // Write the byte stream
    } else {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream javaos = new ObjectOutputStream(bos);
        try {
            javaos.writeObject(object);
        } finally {
            try {
                javaos.close();
            } catch (IOException ioe) {
                //do nothing
            }
        }
        out.writeByte(SERIALIZED_BY_JAVA); // Write serialization type
        out.writeInt(bos.size()); // Write byte stream size
        out.write(bos.toByteArray()); // Write the byte stream
    }
}
 
源代码2 项目: TencentKona-8   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码3 项目: android_tv_metro   文件: DiskBasedCache.java
/**
 * Writes the contents of this CacheHeader to the specified OutputStream.
 */
public boolean writeHeader(OutputStream os) {
    try {
        ObjectOutputStream oos = new ObjectOutputStream(os);
        oos.writeByte(CACHE_VERSION);
        oos.writeUTF(key);
        oos.writeUTF(etag == null ? "" : etag);
        oos.writeLong(serverDate);
        oos.writeLong(ttl);
        oos.writeLong(softTtl);
        writeStringStringMap(responseHeaders, oos);
        oos.flush();
        return true;
    } catch (IOException e) {
        VolleyLog.d("%s", e.toString());
        return false;
    }
}
 
源代码4 项目: jdk8u60   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码5 项目: openjdk-jdk8u   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码6 项目: openbd-core   文件: MemberBox.java
/**
 * 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");
    }
}
 
源代码7 项目: openjdk-jdk9   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码8 项目: jdk8u-jdk   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码9 项目: hottub   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码10 项目: openjdk-8-source   文件: Bytes.java
/**
 * 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.writeByte(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readByte();
        }
    }
}
 
源代码11 项目: jtransc   文件: LogRecord.java
private void writeObject(ObjectOutputStream out) throws IOException {
	out.defaultWriteObject();
	out.writeByte(MAJOR);
	out.writeByte(MINOR);
	if (parameters == null) {
		out.writeInt(-1);
	} else {
		out.writeInt(parameters.length);
		for (Object element : parameters) {
			out.writeObject((element == null) ? null : element.toString());
		}
	}
}
 
源代码12 项目: terracotta-platform   文件: ResponseCodec.java
public static byte[] encode(MapResponse response) throws IOException {
  ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  ObjectOutputStream output = new ObjectOutputStream(byteOut);

  output.writeByte(response.responseType().ordinal());
  response.writeTo(output);

  output.close();
  return byteOut.toByteArray();
}
 
源代码13 项目: jdk8u60   文件: CustomObjTrees.java
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);
}
 
源代码14 项目: openjdk-8-source   文件: CustomObjTrees.java
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);
}
 
源代码15 项目: terracotta-platform   文件: OperationCodec.java
public static byte[] encode(MapOperation operation) throws IOException {
  ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  ObjectOutputStream output = new ObjectOutputStream(byteOut);

  output.writeByte(operation.operationType().ordinal());
  operation.writeTo(output);

  output.close();
  return byteOut.toByteArray();
}
 
源代码16 项目: jdk8u-jdk   文件: CustomObjTrees.java
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);
}
 
源代码17 项目: openjdk-jdk9   文件: CustomObjTrees.java
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);
}
 
源代码18 项目: ysoserial-modified   文件: JRMPListener.java
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();
    }
}
 
源代码19 项目: pentaho-reporting   文件: Element.java
/**
 * A helper method that serializes the element object.
 *
 * @param stream
 *          the stream to which the element should be serialized.
 * @throws IOException
 *           if an IO error occured or a property was not serializable.
 */
private void writeObject( final ObjectOutputStream stream ) throws IOException {
  stream.defaultWriteObject();
  final ReportAttributeMap attributes = this.attributes;
  stream.writeLong( attributes.getChangeTracker() );
  final String[] nameSpaces = attributes.getNameSpaces();
  stream.writeObject( nameSpaces );
  for ( int i = 0; i < nameSpaces.length; i++ ) {
    final String nameSpace = nameSpaces[i];
    final String[] names = attributes.getNames( nameSpace );
    stream.writeObject( names );
    for ( int j = 0; j < names.length; j++ ) {
      final String name = names[j];
      final Object attribute = attributes.getAttribute( nameSpace, name );

      final AttributeMetaData data = getMetaData().getAttributeDescription( nameSpace, name );
      if ( data != null ) {
        if ( data.isTransient() ) {
          stream.writeByte( 1 );
          continue;
        }

        if ( attribute instanceof ResourceKey ) {
          final ResourceKey key = (ResourceKey) attribute;
          final ResourceKey parent = key.getParent();
          if ( AttributeNames.Core.NAMESPACE.equals( nameSpace )
              && ( AttributeNames.Core.CONTENT_BASE.equals( name ) || AttributeNames.Core.SOURCE.equals( name ) ) ) {
            if ( parent != null ) {
              // unwrap the content base attribute. After deserialization, the report assumes the bundle-location
              // as content base, as the bundle will be gone.
              if ( isKeySerializable( parent ) ) {
                stream.writeByte( 0 );
                SerializerHelper.getInstance().writeObject( parent, stream );
              } else {
                stream.writeByte( 1 );
              }
            } else {
              // great, the report was never part of a bundle. That makes life easier and the key should be
              // safely serializable too.

              if ( isKeySerializable( key ) ) {
                stream.writeByte( 0 );
                SerializerHelper.getInstance().writeObject( key, stream );
              } else {
                stream.writeByte( 1 );
              }
            }
          } else {
            if ( "Resource".equals( data.getValueRole() ) || parent != null ) {
              stream.writeByte( 0 );
              try {
                final ResourceKey resourceKey =
                    ResourceKeyUtils.embedResourceInKey( locateResourceManager(), key, key.getFactoryParameters() );
                SerializerHelper.getInstance().writeObject( resourceKey, stream );
              } catch ( ResourceException e ) {
                throw new IOException( "Failed to convert resource-key into byte-array key: " + e );
              }
            } else {
              stream.writeByte( 0 );
              SerializerHelper.getInstance().writeObject( attribute, stream );
            }
          }
        } else if ( SerializerHelper.getInstance().isSerializable( attribute ) ) {
          stream.writeByte( 0 );
          SerializerHelper.getInstance().writeObject( attribute, stream );
        } else {
          stream.writeByte( 1 );
        }
      } else if ( attribute instanceof String ) {
        stream.writeByte( 0 );
        SerializerHelper.getInstance().writeObject( attribute, stream );
      } else {
        stream.writeByte( 1 );
      }
    }
  }
}
 
源代码20 项目: visualvm   文件: MonitoredNumbersResponse.java
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(mode);
    for (int i = 0; i < generalNumbers.length; i++) {
        out.writeLong(generalNumbers[i]);
    }

    if (mode == CommonConstants.MODE_THREADS_SAMPLING) {
        out.writeInt(nThreads);
        out.writeInt(nThreadStates);
        for (int i = 0; i < nThreads; i++) {
            out.writeInt(threadIds[i]);
        }
        for (int i = 0; i < nThreadStates; i++) {
            out.writeLong(stateTimestamps[i]);
        }
        int len = nThreads * nThreadStates;
        out.write(threadStates, 0, len);
    } else if (mode == CommonConstants.MODE_THREADS_EXACT) {
        out.writeInt(exactThreadStates.length);
        for (int i = 0; i < exactThreadIds.length; i++) {
            out.writeInt(exactThreadIds[i]);
            out.writeByte(exactThreadStates[i]);
            out.writeLong(exactTimeStamps[i]);
        }
    }

    if (nNewThreads == 0) {
        out.writeInt(0);
    } else {
        out.writeInt(nNewThreads);

        for (int i = 0; i < nNewThreads; i++) {
            out.writeInt(newThreadIds[i]);
            out.writeUTF(newThreadNames[i]);
            out.writeUTF(newThreadClassNames[i]);
        }
    }

    out.writeInt(gcStarts.length);

    for (int i = 0; i < gcStarts.length; i++) {
        out.writeLong(gcStarts[i]);
    }

    out.writeInt(gcFinishs.length);

    for (int i = 0; i < gcFinishs.length; i++) {
        out.writeLong(gcFinishs[i]);
    }

    out.writeInt(serverState);
    out.writeInt(serverProgress);
}