下面列出了java.io.ObjectOutputStream#writeLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private byte [] marshallThingy(DataObject thingy ) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(baos);
stream.writeChar(thingy.type);
stream.writeLong(thingy.time);
if( thingy.intCount != null ) {
stream.writeInt(thingy.intCount);
}
else if( thingy.strCount != null ) {
stream.writeUTF(thingy.strCount);
}
else {
throw new IllegalStateException("Neither the integer nor String count is filled." );
}
stream.close();
return baos.toByteArray();
}
private void writeObject(ObjectOutputStream out) throws IOException
{
if (!(bean instanceof PassivationCapable))
{
throw new NotSerializableException("Bean is not PassivationCapable: " + bean.toString());
}
String passivationId = ((PassivationCapable) bean).getId();
if (passivationId == null)
{
throw new NotSerializableException(bean.toString());
}
out.writeLong(serialVersionUID);
out.writeObject(passivationId);
out.writeObject(instance);
out.writeObject(creationalContext);
}
private static void writeKnownIDs(ObjectOutputStream out, FastByIDMap<FastIDSet> knownItemIDs) throws IOException {
if (knownItemIDs == null) {
out.writeInt(NULL_COUNT);
} else {
out.writeInt(knownItemIDs.size());
for (FastByIDMap.MapEntry<FastIDSet> entry : knownItemIDs.entrySet()) {
out.writeLong(entry.getKey());
FastIDSet itemIDs = entry.getValue();
out.writeInt(itemIDs.size());
LongPrimitiveIterator it = itemIDs.iterator();
while (it.hasNext()) {
out.writeLong(it.nextLong());
}
}
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getCommentURL());
out.writeObject(cookie.getDomain());
out.writeLong(cookie.getMaxAge());
out.writeObject(cookie.getPath());
out.writeObject(cookie.getPortlist());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.getSecure());
out.writeBoolean(cookie.getDiscard());
out.writeBoolean(getHttpOnly());
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getCommentURL());
out.writeObject(cookie.getDomain());
out.writeLong(cookie.getMaxAge());
out.writeObject(cookie.getPath());
out.writeObject(cookie.getPortlist());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.getSecure());
out.writeBoolean(cookie.getDiscard());
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getCommentURL());
out.writeObject(cookie.getDomain());
out.writeLong(cookie.getMaxAge());
out.writeObject(cookie.getPath());
out.writeObject(cookie.getPortlist());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.getSecure());
out.writeBoolean(cookie.getDiscard());
out.writeBoolean(getHttpOnly());
}
/** Custom serialization */
private void writeObject(ObjectOutputStream os) throws IOException {
os.writeInt(length);
os.writeLong(defaultCode);
os.writeObject(defaultValue);
os.writeObject(coding);
for (int i=0; i<length; ++i) {
final long value = buffer.get(i);
os.writeLong(value);
}
}
/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData The value returned by {@code getTime()}
* is emitted (long). This represents the offset from
* January 1, 1970, 00:00:00 GMT in milliseconds.
*/
@java.io.Serial
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
s.writeLong(getTimeImpl());
}
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);
}
@Override
public final void write(ObjectOutputStream os, int[] indexes) throws IOException {
for (int index : indexes) {
final long value = getLong(index);
os.writeLong(value);
}
}
private void writeObject(ObjectOutputStream out) throws IOException
{
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getCommentURL());
out.writeObject(cookie.getDomain());
out.writeLong(cookie.getMaxAge());
out.writeObject(cookie.getPath());
out.writeObject(cookie.getPortlist());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.getSecure());
out.writeBoolean(cookie.getDiscard());
}
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);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(cookie.name());
out.writeObject(cookie.value());
out.writeLong(cookie.expiresAt());
out.writeObject(cookie.domain());
out.writeObject(cookie.path());
out.writeBoolean(cookie.secure());
out.writeBoolean(cookie.httpOnly());
out.writeBoolean(cookie.hostOnly());
out.writeBoolean(cookie.persistent());
}
/**
* Save the state of the <code>SparseBitSet</code> instance to a stream
* (<i>i.e.</i>, serialize it).
*
* @param s the ObjectOutputStream to which to write the serialized object
* @exception java.io.IOException if an io error occurs
* @exception java.lang.InternalError if the SparseBitSet representation is
* inconsistent
*
* @serialData The default data is emitted, followed by the current
* <i>compactionCount</i> for the bit set, and then the
* <i>length</i> of the set (the position of the last bit),
* followed by the <i>cache.count</i> value (an <code>int</code>,
* the number of <code>int->long</code> pairs needed to describe
* the set), followed by the index (<code>int</code>) and word
* (<code>long</code>) for each <code>int->long</code> pair.
* The mappings need not be emitted in any particular order. This
* is followed by the <i>hashCode</i> for the set that can be used
* as an integrity check when the bit set is read back.
*
* @since 1.6
*/
private void writeObject(ObjectOutputStream s) throws IOException, InternalError
{
statisticsUpdate(); // Update structure and stats if needed.
/* Write any hidden stuff. */
s.defaultWriteObject();
s.writeInt(compactionCount); // Needed to preserve value
s.writeInt(cache.length); // Needed to know where last bit is
/* This is the number of index/value pairs to be written. */
int count = cache.count; // Minimum number of words to be written
s.writeInt(count);
final long[][][] a1 = bits;
final int aLength1 = a1.length;
long[][] a2;
long[] a3;
long word;
for (int w1 = 0; w1 != aLength1; ++w1)
if ((a2 = a1[w1]) != null)
for (int w2 = 0; w2 != LENGTH2; ++w2)
if ((a3 = a2[w2]) != null)
{
final int base = (w1 << SHIFT1) + (w2 << SHIFT2);
for (int w3 = 0; w3 != LENGTH3; ++w3)
if ((word = a3[w3]) != 0)
{
s.writeInt(base + w3);
s.writeLong(word);
--count;
}
}
if (count != 0)
throw new InternalError("count of entries not consistent");
/* As a consistency check, write the hash code of the set. */
s.writeInt(cache.hash);
}
/**
* 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 );
}
}
}
}
private void writeObject(ObjectOutputStream stream) throws IOException
{
stream.writeLong(get());
}
/**
* Serializes fragment metadata into a ByteArrayOutputStream
*
* @param start the fragment metadata start
* @param length the fragment metadata length
* @param locations the data node locations for this split
* @return byte serialization of the file split
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
private static ByteArrayOutputStream writeBaseFragmentInfo(long start, long length, String[] locations)
throws IOException {
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
ObjectOutputStream objectStream = new ObjectOutputStream(byteArrayStream);
objectStream.writeLong(start);
objectStream.writeLong(length);
objectStream.writeObject(locations);
return byteArrayStream;
}
/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData The value returned by <code>getTime()</code>
* is emitted (long). This represents the offset from
* January 1, 1970, 00:00:00 GMT in milliseconds.
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.writeLong(getTimeImpl());
}
/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData The value returned by <code>getTime()</code>
* is emitted (long). This represents the offset from
* January 1, 1970, 00:00:00 GMT in milliseconds.
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.writeLong(getTimeImpl());
}
/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData The value returned by <code>getTime()</code>
* is emitted (long). This represents the offset from
* January 1, 1970, 00:00:00 GMT in milliseconds.
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.writeLong(getTimeImpl());
}