下面列出了java.io.ObjectOutputStream#writeUTF ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void lookupName(String cmd, InputStream ins, OutputStream outs)
throws IOException
{
ObjectInputStream in = new ObjectInputStream(ins);
String name = DataInputStream.readUTF(in);
ExportedObject found = exportedNames.get(name);
outs.write(okHeader);
ObjectOutputStream out = new ObjectOutputStream(outs);
if (found == null) {
logging2(name + "not found.");
out.writeInt(-1); // error code
out.writeUTF("error");
}
else {
logging2(name);
out.writeInt(found.identifier);
out.writeUTF(found.object.getClass().getName());
}
out.flush();
out.close();
in.close();
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeUTF(methodName);
oos.writeInt(parameterTypes.length);
for (Class<?> parameterType : parameterTypes) {
oos.writeObject(parameterType);
}
if (args != null) {
oos.writeBoolean(true);
for (int i = 0; i < args.length; i++) {
try {
oos.writeObject(args[i]);
} catch (IOException e) {
throw new IOException("Could not serialize " + i + "th argument of method " +
methodName + ". This indicates that the argument type " +
args.getClass().getName() + " is not serializable. Arguments have to " +
"be serializable for remote rpc calls.", e);
}
}
} else {
oos.writeBoolean(false);
}
}
/**
* 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;
}
}
void writeObject(ObjectOutputStream out) throws IOException {
out.writeLong(time.getTime());
out.writeInt(newNames.length);
for (int i = 0; i < newNames.length; i++) {
out.writeUTF(newNames[i]);
}
out.writeInt(newids.length);
for (int i = 0; i < newids.length; i++) {
out.writeInt(newids[i]);
}
out.writeInt(ids.length);
for (int i = 0; i < ids.length; i++) {
out.writeInt(ids[i]);
}
out.writeInt(instances.length);
for (int i = 0; i < instances.length; i++) {
out.writeLong(instances[i]);
}
out.writeInt(bytes.length);
for (int i = 0; i < bytes.length; i++) {
out.writeLong(bytes[i]);
}
newNames = null;
newids = null;
ids = null;
instances = null;
bytes = null;
}
@Override
public void saveModel(ObjectOutputStream out) {
// TODO Auto-generated method stub
try {
out.writeUTF(getType());
//�����ʱ��batchҲ����layerParams��number����1����Ϊpredict��ʱ����Ϊ����ʹ�õ�ʱ�����batchһ�㶼��1
out.writeInt(width);
out.writeInt(height);
out.writeInt(channel);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Custom serializer.
*
* @param oos
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
oos.writeLong(latticeSourceId);
oos.writeDouble(score);
oos.writeUTF(source.toString());
oos.writeUTF(translation.toString());
oos.writeUTF(f2eAlignment == null ? alignmentString() : f2eAlignment);
oos.writeObject(this.features);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(this.fieldNames.length);
for (String fieldName : this.fieldNames) {
out.writeUTF(fieldName);
}
this.configuration.write(out);
}
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
getFormattedMessage();
out.writeUTF(formattedMessage);
out.writeUTF(messagePattern);
out.writeInt(argArray.length);
stringArgs = new String[argArray.length];
int i = 0;
for (final Object obj : argArray) {
final String string = String.valueOf(obj);
stringArgs[i] = string;
out.writeUTF(string);
++i;
}
}
public void write(ObjectOutputStream os,
Object object) throws IOException {
ProcessInstance processInstance = (ProcessInstance) object;
connectProcessInstanceToRuntimeAndProcess( processInstance, os );
os.writeUTF( processInstance.getId() );
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(this.fieldNames.length);
for (String fieldName : this.fieldNames) {
out.writeUTF(fieldName);
}
this.configuration.write(out);
}
/**
* 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);
}
}
private void writeObject(ObjectOutputStream oos) throws IOException {
LOG.trace("Serializing many references {}", this);
oos.writeUTF(entityType.getInterfaceName());
oos.writeBoolean(fetched);
oos.writeObject(entities);
oos.writeObject(newEntities);
}
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for
* this class as follows:
*
* <p>The <code>writeObject</code> method is invoked on
* <code>out</code> passing this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance) as the argument.
*
* <p>Next, the {@link
* java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
* getRefClass} method is invoked on the activator's
* <code>RemoteRef</code> instance to obtain its external ref
* type name. Next, the <code>writeUTF</code> method is
* invoked on <code>out</code> with the value returned by
* <code>getRefClass</code>, and then the
* <code>writeExternal</code> method is invoked on the
* <code>RemoteRef</code> instance passing <code>out</code>
* as the argument.
*
* @serialData The serialized data for this class comprises a
* <code>java.rmi.server.UID</code> (written with
* <code>ObjectOutput.writeObject</code>) followed by the
* external ref type name of the activator's
* <code>RemoteRef</code> instance (a string written with
* <code>ObjectOutput.writeUTF</code>), followed by the
* external form of the <code>RemoteRef</code> instance as
* written by its <code>writeExternal</code> method.
*
* <p>The external ref type name of the
* <code>RemoteRef</Code> instance is
* determined using the definitions of external ref type
* names specified in the {@link java.rmi.server.RemoteObject
* RemoteObject} <code>writeObject</code> method
* <b>serialData</b> specification. Similarly, the data
* written by the <code>writeExternal</code> method and read
* by the <code>readExternal</code> method of
* <code>RemoteRef</code> implementation classes
* corresponding to each of the defined external ref type
* names is specified in the {@link
* java.rmi.server.RemoteObject RemoteObject}
* <code>writeObject</code> method <b>serialData</b>
* specification.
**/
private void writeObject(ObjectOutputStream out)
throws IOException, ClassNotFoundException
{
out.writeObject(uid);
RemoteRef ref;
if (activator instanceof RemoteObject) {
ref = ((RemoteObject) activator).getRef();
} else if (Proxy.isProxyClass(activator.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(activator);
if (!(handler instanceof RemoteObjectInvocationHandler)) {
throw new InvalidObjectException(
"unexpected invocation handler");
}
ref = ((RemoteObjectInvocationHandler) handler).getRef();
} else {
throw new InvalidObjectException("unexpected activator type");
}
out.writeUTF(ref.getRefClass(out));
ref.writeExternal(out);
}
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);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(iID);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(iID);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeUTF(params.getId());
}
void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(className);
out.writeInt(classLoaderId);
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeUTF(toCustomString());
}
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for
* this class as follows:
*
* <p>The <code>writeObject</code> method is invoked on
* <code>out</code> passing this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance) as the argument.
*
* <p>Next, the {@link
* java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
* getRefClass} method is invoked on the activator's
* <code>RemoteRef</code> instance to obtain its external ref
* type name. Next, the <code>writeUTF</code> method is
* invoked on <code>out</code> with the value returned by
* <code>getRefClass</code>, and then the
* <code>writeExternal</code> method is invoked on the
* <code>RemoteRef</code> instance passing <code>out</code>
* as the argument.
*
* @serialData The serialized data for this class comprises a
* <code>java.rmi.server.UID</code> (written with
* <code>ObjectOutput.writeObject</code>) followed by the
* external ref type name of the activator's
* <code>RemoteRef</code> instance (a string written with
* <code>ObjectOutput.writeUTF</code>), followed by the
* external form of the <code>RemoteRef</code> instance as
* written by its <code>writeExternal</code> method.
*
* <p>The external ref type name of the
* <code>RemoteRef</Code> instance is
* determined using the definitions of external ref type
* names specified in the {@link java.rmi.server.RemoteObject
* RemoteObject} <code>writeObject</code> method
* <b>serialData</b> specification. Similarly, the data
* written by the <code>writeExternal</code> method and read
* by the <code>readExternal</code> method of
* <code>RemoteRef</code> implementation classes
* corresponding to each of the defined external ref type
* names is specified in the {@link
* java.rmi.server.RemoteObject RemoteObject}
* <code>writeObject</code> method <b>serialData</b>
* specification.
**/
private void writeObject(ObjectOutputStream out)
throws IOException, ClassNotFoundException
{
out.writeObject(uid);
RemoteRef ref;
if (activator instanceof RemoteObject) {
ref = ((RemoteObject) activator).getRef();
} else if (Proxy.isProxyClass(activator.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(activator);
if (!(handler instanceof RemoteObjectInvocationHandler)) {
throw new InvalidObjectException(
"unexpected invocation handler");
}
ref = ((RemoteObjectInvocationHandler) handler).getRef();
} else {
throw new InvalidObjectException("unexpected activator type");
}
out.writeUTF(ref.getRefClass(out));
ref.writeExternal(out);
}