本文整理汇总了Java中org.apache.hadoop.hdfs.util.ByteBufferOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferOutputStream类的具体用法?Java ByteBufferOutputStream怎么用?Java ByteBufferOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteBufferOutputStream类属于org.apache.hadoop.hdfs.util包,在下文中一共展示了ByteBufferOutputStream类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureTextSet
import org.apache.hadoop.hdfs.util.ByteBufferOutputStream; //导入依赖的package包/类
/**
* Ensures that either the UTF-8 text has been set directly or by indirectly converting the Map contents to JSON.
*/
private void ensureTextSet() {
if (_text.limit() == 0) {
checkState(_map != null, "Neither JSON text nor map has been set");
_text.clear();
// First try reading the JSON directly into be buffer.
try {
JsonHelper.writeJson(new ByteBufferOutputStream(_text), _map);
// Set the limit and move the position back to zero.
_text.flip();
} catch (Exception e) {
if (Iterables.tryFind(Throwables.getCausalChain(e), Predicates.instanceOf(BufferOverflowException.class)).isPresent()) {
// Buffer was insufficient. Allocate a new array and read the bytes into it.
byte[] utf8 = JsonHelper.asUtf8Bytes(_map);
_text = ByteBuffer.wrap(utf8);
} else {
throw Throwables.propagate(e);
}
}
}
}