org.apache.hadoop.io.UTF8.writeChars()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(174)

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

UTF8.writeChars介绍

暂无

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, bytes, 0, length);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: io.hops/hadoop-common

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/** Write a UTF-8 encoded string.
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
 if (s.length() > 0xffff/3) {         // maybe too long
  LOG.warn("truncating long string: " + s.length()
       + " chars, starting with " + s.substring(0, 20));
  s = s.substring(0, 0xffff/3);
 }
 int len = utf8Length(s);
 if (len > 0xffff)                             // double-check length
  throw new IOException("string too long!");
  
 out.writeShort(len);
 writeChars(out, s, 0, s.length());
 return len;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, bytes, 0, length);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, bytes, 0, length);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, bytes, 0, length);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: io.hops/hadoop-common

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, bytes, 0, length);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core

/** Set to contain the contents of a string. */
public void set(String string) {
 if (string.length() > 0xffff/3) {             // maybe too long
  LOG.warn("truncating long string: " + string.length()
       + " chars, starting with " + string.substring(0, 20));
  string = string.substring(0, 0xffff/3);
 }
 length = utf8Length(string);                  // compute length
 if (length > 0xffff)                          // double-check length
  throw new RuntimeException("string too long!");
 if (bytes == null || length > bytes.length)   // grow buffer
  bytes = new byte[length];
 try {                                         // avoid sync'd allocations
  synchronized (OBUF) {
   OBUF.reset();
   writeChars(OBUF, string, 0, string.length());
   System.arraycopy(OBUF.getData(), 0, bytes, 0, length);
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: io.hops/hadoop-common

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  DataOutputBuffer obuf = OBUF_FACTORY.get();
  obuf.reset();
  writeChars(obuf, string, 0, string.length());
  System.arraycopy(obuf.getData(), 0, result, 0, obuf.getLength());
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core

/** Convert a string to a UTF-8 encoded byte array.
 * @see String#getBytes(String)
 */
public static byte[] getBytes(String string) {
 byte[] result = new byte[utf8Length(string)];
 try {                                         // avoid sync'd allocations
  synchronized (OBUF) {
   OBUF.reset();
   writeChars(OBUF, string, 0, string.length());
   System.arraycopy(OBUF.getData(), 0, result, 0, OBUF.getLength());
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return result;
}

相关文章