WriteString() public method

Writes a string.

Writes strings as UTF-8 encoded bytes. First the length, in bytes, is written as a #writeVInt VInt, followed by the bytes.

public WriteString ( string s ) : void
s string
return void
示例#1
0
 /// <summary>
 /// Writes a codec header, which records both a string to
 /// identify the file and a version number. this header can
 /// be parsed and validated with
 /// <seealso cref="#checkHeader(DataInput, String, int, int) checkHeader()"/>.
 /// <p>
 /// CodecHeader --&gt; Magic,CodecName,Version
 /// <ul>
 ///    <li>Magic --&gt; <seealso cref="DataOutput#writeInt Uint32"/>. this
 ///        identifies the start of the header. It is always {@value #CODEC_MAGIC}.
 ///    <li>CodecName --&gt; <seealso cref="DataOutput#writeString String"/>. this
 ///        is a string to identify this file.
 ///    <li>Version --&gt; <seealso cref="DataOutput#writeInt Uint32"/>. Records
 ///        the version of the file.
 /// </ul>
 /// <p>
 /// Note that the length of a codec header depends only upon the
 /// name of the codec, so this length can be computed at any time
 /// with <seealso cref="#headerLength(String)"/>.
 /// </summary>
 /// <param name="out"> Output stream </param>
 /// <param name="codec"> String to identify this file. It should be simple ASCII,
 ///              less than 128 characters in length. </param>
 /// <param name="version"> Version number </param>
 /// <exception cref="IOException"> If there is an I/O error writing to the underlying medium. </exception>
 public static void WriteHeader(DataOutput @out, string codec, int version)
 {
     BytesRef bytes = new BytesRef(codec);
     if (bytes.Length != codec.Length || bytes.Length >= 128)
     {
         throw new System.ArgumentException("codec must be simple ASCII, less than 128 characters in length [got " + codec + "]");
     }
     @out.WriteInt(CODEC_MAGIC);
     @out.WriteString(codec);
     @out.WriteInt(version);
 }
示例#2
0
 // pre-order traversal
 private void WriteRecursively(DataOutput @out, TernaryTreeNode node)
 {
     // write out the current node
     @out.WriteString(new string(new char[] { node.splitchar }, 0, 1));
     // prepare a mask of kids
     sbyte mask = 0;
     if (node.eqKid != null)
     {
         mask |= EQ_KID;
     }
     if (node.loKid != null)
     {
         mask |= LO_KID;
     }
     if (node.hiKid != null)
     {
         mask |= HI_KID;
     }
     if (node.token != null)
     {
         mask |= HAS_TOKEN;
     }
     if (node.val != null)
     {
         mask |= HAS_VALUE;
     }
     @out.WriteByte((byte)mask);
     if (node.token != null)
     {
         @out.WriteString(node.token);
     }
     if (node.val != null)
     {
         @out.WriteLong((long)node.val);
     }
     // recurse and write kids
     if (node.loKid != null)
     {
         WriteRecursively(@out, node.loKid);
     }
     if (node.eqKid != null)
     {
         WriteRecursively(@out, node.eqKid);
     }
     if (node.hiKid != null)
     {
         WriteRecursively(@out, node.hiKid);
     }
 }
 private void WriteRecursively(DataOutput @out, JaspellTernarySearchTrie.TSTNode node)
 {
     if (node == null)
     {
         return;
     }
     @out.WriteString(new string(new char[] { node.splitchar }, 0, 1));
     sbyte mask = 0;
     if (node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] != null)
     {
         mask |= LO_KID;
     }
     if (node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID] != null)
     {
         mask |= EQ_KID;
     }
     if (node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID] != null)
     {
         mask |= HI_KID;
     }
     if (node.data != null)
     {
         mask |= HAS_VALUE;
     }
     @out.WriteByte((byte)mask);
     if (node.data != null)
     {
         @out.WriteLong((long)(node.data));
     }
     WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID]);
     WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID]);
     WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID]);
 }