Example #1
0
  /** write the string as tag+length, with length being the number of UTF-8 bytes */
  public void writeStr(String s) throws IOException {
    if (s == null) {
      writeTag(NULL);
      return;
    }
    int end = s.length();
    int maxSize = end * ByteUtils.MAX_UTF8_BYTES_PER_CHAR;

    if (maxSize <= MAX_UTF8_SIZE_FOR_ARRAY_GROW_STRATEGY) {
      if (bytes == null || bytes.length < maxSize) bytes = new byte[maxSize];
      int sz = ByteUtils.UTF16toUTF8(s, 0, end, bytes, 0);
      writeTag(STR, sz);
      daos.write(bytes, 0, sz);
    } else {
      // double pass logic for large strings, see SOLR-7971
      int sz = ByteUtils.calcUTF16toUTF8Length(s, 0, end);
      writeTag(STR, sz);
      if (bytes == null || bytes.length < 8192) bytes = new byte[8192];
      ByteUtils.writeUTF16toUTF8(s, 0, end, daos, bytes);
    }
  }
Example #2
0
 @Override
 public void write(byte b[]) throws IOException {
   write(b, 0, b.length);
 }
Example #3
0
 public void writeByteArray(byte[] arr, int offset, int len) throws IOException {
   writeTag(BYTEARR, len);
   daos.write(arr, offset, len);
 }
Example #4
0
 @Override
 public void write(int b) throws IOException {
   write((byte) b);
 }
Example #5
0
 @Override
 public void writeBytes(String s) throws IOException {
   // non-optimized version, but this shouldn't be used anyway
   for (int i = 0; i < s.length(); i++) write((byte) s.charAt(i));
 }
Example #6
0
 @Override
 public void writeShort(int v) throws IOException {
   write((byte) (v >>> 8));
   write((byte) v);
 }
Example #7
0
 @Override
 public void writeByte(int v) throws IOException {
   write((byte) v);
 }
Example #8
0
 ////////////////// DataOutput methods ///////////////////
 @Override
 public void writeBoolean(boolean v) throws IOException {
   write(v ? 1 : 0);
 }