本文整理了Java中org.apache.hadoop.hbase.util.Bytes.writeStringFixedSize()
方法的一些代码示例,展示了Bytes.writeStringFixedSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.writeStringFixedSize()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:writeStringFixedSize
[英]Writes a string as a fixed-size field, padded with zeros.
[中]将字符串作为固定大小的字段写入,并用零填充。
代码示例来源:origin: apache/hbase
public void testFixedSizeString() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
Bytes.writeStringFixedSize(dos, "Hello", 5);
Bytes.writeStringFixedSize(dos, "World", 18);
Bytes.writeStringFixedSize(dos, "", 9);
try {
// Use a long dash which is three bytes in UTF-8. If encoding happens
// using ISO-8859-1, this will fail.
Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9);
fail("Exception expected");
} catch (IOException ex) {
assertEquals(
"Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " +
"length 9", ex.getMessage());
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais);
assertEquals("Hello", Bytes.readStringFixedSize(dis, 5));
assertEquals("World", Bytes.readStringFixedSize(dis, 18));
assertEquals("", Bytes.readStringFixedSize(dis, 9));
}
代码示例来源:origin: apache/hbase
private void serializeAsWritable(DataOutputStream output, FixedFileTrailer fft)
throws IOException {
BlockType.TRAILER.write(output);
output.writeLong(fft.getFileInfoOffset());
output.writeLong(fft.getLoadOnOpenDataOffset());
output.writeInt(fft.getDataIndexCount());
output.writeLong(fft.getUncompressedDataIndexSize());
output.writeInt(fft.getMetaIndexCount());
output.writeLong(fft.getTotalUncompressedBytes());
output.writeLong(fft.getEntryCount());
output.writeInt(fft.getCompressionCodec().ordinal());
output.writeInt(fft.getNumDataIndexLevels());
output.writeLong(fft.getFirstDataBlockOffset());
output.writeLong(fft.getLastDataBlockOffset());
Bytes.writeStringFixedSize(output, fft.getComparatorClassName(), MAX_COMPARATOR_NAME_LENGTH);
output.writeInt(FixedFileTrailer.materializeVersion(fft.getMajorVersion(),
fft.getMinorVersion()));
}
代码示例来源:origin: co.cask.hbase/hbase
baosDos.writeLong(firstDataBlockOffset);
baosDos.writeLong(lastDataBlockOffset);
Bytes.writeStringFixedSize(baosDos, comparatorClassName,
MAX_COMPARATOR_NAME_LENGTH);
代码示例来源:origin: org.apache.hbase/hbase-common
public void testFixedSizeString() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
Bytes.writeStringFixedSize(dos, "Hello", 5);
Bytes.writeStringFixedSize(dos, "World", 18);
Bytes.writeStringFixedSize(dos, "", 9);
try {
// Use a long dash which is three bytes in UTF-8. If encoding happens
// using ISO-8859-1, this will fail.
Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9);
fail("Exception expected");
} catch (IOException ex) {
assertEquals(
"Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " +
"length 9", ex.getMessage());
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais);
assertEquals("Hello", Bytes.readStringFixedSize(dis, 5));
assertEquals("World", Bytes.readStringFixedSize(dis, 18));
assertEquals("", Bytes.readStringFixedSize(dis, 9));
}
代码示例来源:origin: com.aliyun.hbase/alihbase-common
public void testFixedSizeString() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
Bytes.writeStringFixedSize(dos, "Hello", 5);
Bytes.writeStringFixedSize(dos, "World", 18);
Bytes.writeStringFixedSize(dos, "", 9);
try {
// Use a long dash which is three bytes in UTF-8. If encoding happens
// using ISO-8859-1, this will fail.
Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9);
fail("Exception expected");
} catch (IOException ex) {
assertEquals(
"Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " +
"length 9", ex.getMessage());
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais);
assertEquals("Hello", Bytes.readStringFixedSize(dis, 5));
assertEquals("World", Bytes.readStringFixedSize(dis, 18));
assertEquals("", Bytes.readStringFixedSize(dis, 9));
}
代码示例来源:origin: org.apache.hbase/hbase-server
private void serializeAsWritable(DataOutputStream output, FixedFileTrailer fft)
throws IOException {
BlockType.TRAILER.write(output);
output.writeLong(fft.getFileInfoOffset());
output.writeLong(fft.getLoadOnOpenDataOffset());
output.writeInt(fft.getDataIndexCount());
output.writeLong(fft.getUncompressedDataIndexSize());
output.writeInt(fft.getMetaIndexCount());
output.writeLong(fft.getTotalUncompressedBytes());
output.writeLong(fft.getEntryCount());
output.writeInt(fft.getCompressionCodec().ordinal());
output.writeInt(fft.getNumDataIndexLevels());
output.writeLong(fft.getFirstDataBlockOffset());
output.writeLong(fft.getLastDataBlockOffset());
Bytes.writeStringFixedSize(output, fft.getComparatorClassName(), MAX_COMPARATOR_NAME_LENGTH);
output.writeInt(FixedFileTrailer.materializeVersion(fft.getMajorVersion(),
fft.getMinorVersion()));
}
内容来源于网络,如有侵权,请联系作者删除!