java.io.ObjectOutputStream.writeString()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中java.io.ObjectOutputStream.writeString()方法的一些代码示例,展示了ObjectOutputStream.writeString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectOutputStream.writeString()方法的具体详情如下:
包路径:java.io.ObjectOutputStream
类名称:ObjectOutputStream
方法名:writeString

ObjectOutputStream.writeString介绍

[英]Writes given string to stream, using standard or long UTF format depending on string length.
[中]根据字符串长度,使用标准或长UTF格式将给定字符串写入流。

代码示例

代码示例来源:origin: stackoverflow.com

out.writeString(nvp.getName());
out.writeString(nvp.getValue());

代码示例来源:origin: stackoverflow.com

public class MyClass {
 private static final int CUR_VERSION = 5;
 private String _value;

 private void readObject(ObjectInputStream in) {
  // first value is always the serial version:
  int dataVersion = in.readInt();
  if(dataVersion == CUR_VERSION) {
   // _value is a String
   _value = in.readString();
  } else {
   // in older versions, _value was an int
   _value = String.valueOf(in.readInt());
  }
 }

 private void writeObject(ObjectOutputStream out) {
  // always write version first
  out.writeInt(CUR_VERSION);
  out.writeString(_value);
 }
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Writes string without allowing it to be replaced in stream.  Used by
 * ObjectStreamClass to write class descriptor type strings.
 */
void writeTypeString(String str) throws IOException {
  int handle;
  if (str == null) {
    writeNull();
  } else if ((handle = handles.lookup(str)) != -1) {
    writeHandle(handle);
  } else {
    writeString(str, false);
  }
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Writes string without allowing it to be replaced in stream.  Used by
 * ObjectStreamClass to write class descriptor type strings.
 */
void writeTypeString(String str) throws IOException {
  int handle;
  if (str == null) {
    writeNull();
  } else if ((handle = handles.lookup(str)) != -1) {
    writeHandle(handle);
  } else {
    writeString(str, false);
  }
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Writes given enum constant to stream.
 */
private void writeEnum(Enum en,
            ObjectStreamClass desc,
            boolean unshared)
  throws IOException
{
  bout.writeByte(TC_ENUM);
  ObjectStreamClass sdesc = desc.getSuperDesc();
  writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false);
  handles.assign(unshared ? null : en);
  writeString(en.name(), false);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Writes given enum constant to stream.
 */
private void writeEnum(Enum en,
            ObjectStreamClass desc,
            boolean unshared)
  throws IOException
{
  bout.writeByte(TC_ENUM);
  ObjectStreamClass sdesc = desc.getSuperDesc();
  writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false);
  handles.assign(unshared ? null : en);
  writeString(en.name(), false);
}

代码示例来源:origin: jtulach/bck2brwsr

writeString((String) obj, unshared);
} else if (cl.isArray()) {
  writeArray(obj, desc, unshared);

代码示例来源:origin: org.apidesign.bck2brwsr/emul

writeString((String) obj, unshared);
} else if (cl.isArray()) {
  writeArray(obj, desc, unshared);

相关文章

ObjectOutputStream类方法