本文整理汇总了Java中io.airlift.slice.Slice.getInput方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.getInput方法的具体用法?Java Slice.getInput怎么用?Java Slice.getInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.airlift.slice.Slice
的用法示例。
在下文中一共展示了Slice.getInput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NumericHistogram
import io.airlift.slice.Slice; //导入方法依赖的package包/类
public NumericHistogram(Slice serialized, int buffer)
{
requireNonNull(serialized, "serialized is null");
checkArgument(buffer >= 1, "buffer must be >= 1");
SliceInput input = serialized.getInput();
checkArgument(input.readByte() == FORMAT_TAG, "Unsupported format tag");
maxBuckets = input.readInt();
nextIndex = input.readInt();
values = new double[maxBuckets + buffer];
weights = new double[maxBuckets + buffer];
input.readBytes(Slices.wrappedDoubleArray(values), nextIndex * SizeOf.SIZE_OF_DOUBLE);
input.readBytes(Slices.wrappedDoubleArray(weights), nextIndex * SizeOf.SIZE_OF_DOUBLE);
}
示例2: deserialize
import io.airlift.slice.Slice; //导入方法依赖的package包/类
public static StringClassifierAdapter deserialize(byte[] data)
{
Slice slice = Slices.wrappedBuffer(data);
BasicSliceInput input = slice.getInput();
int classifierLength = input.readInt();
Model classifier = ModelUtils.deserialize(input.readSlice(classifierLength));
int numEnumerations = input.readInt();
ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();
for (int i = 0; i < numEnumerations; i++) {
int key = input.readInt();
int valueLength = input.readInt();
String value = input.readSlice(valueLength).toStringUtf8();
builder.put(key, value);
}
return new StringClassifierAdapter(checkType(classifier, Classifier.class, "classifier"), builder.build());
}
示例3: advance
import io.airlift.slice.Slice; //导入方法依赖的package包/类
private void advance()
throws IOException
{
if (compressedSliceInput == null || compressedSliceInput.remaining() == 0) {
current = null;
return;
}
// 3 byte header
// NOTE: this must match BLOCK_HEADER_SIZE
currentCompressedBlockOffset = Ints.checkedCast(compressedSliceInput.position());
int b0 = compressedSliceInput.readUnsignedByte();
int b1 = compressedSliceInput.readUnsignedByte();
int b2 = compressedSliceInput.readUnsignedByte();
boolean isUncompressed = (b0 & 0x01) == 1;
int chunkLength = (b2 << 15) | (b1 << 7) | (b0 >>> 1);
Slice chunk = compressedSliceInput.readSlice(chunkLength);
if (isUncompressed) {
current = chunk.getInput();
}
else {
int uncompressedSize;
if (compressionKind == ZLIB) {
uncompressedSize = decompressZip(chunk);
}
else {
uncompressedSize = decompressSnappy(chunk);
}
current = Slices.wrappedBuffer(buffer, 0, uncompressedSize).getInput();
}
}
示例4: OrcReader
import io.airlift.slice.Slice; //导入方法依赖的package包/类
public OrcReader(OrcDataSource orcDataSource, MetadataReader metadataReader, DataSize maxMergeDistance, DataSize maxReadSize)
throws IOException
{
orcDataSource = wrapWithCacheIfTiny(requireNonNull(orcDataSource, "orcDataSource is null"), maxMergeDistance);
this.orcDataSource = orcDataSource;
this.metadataReader = requireNonNull(metadataReader, "metadataReader is null");
this.maxMergeDistance = requireNonNull(maxMergeDistance, "maxMergeDistance is null");
this.maxReadSize = requireNonNull(maxReadSize, "maxReadSize is null");
//
// Read the file tail:
//
// variable: Footer
// variable: Metadata
// variable: PostScript - contains length of footer and metadata
// 3 bytes: file magic "ORC"
// 1 byte: postScriptSize = PostScript + Magic
// figure out the size of the file using the option or filesystem
long size = orcDataSource.getSize();
if (size <= 0) {
throw new OrcCorruptionException("Malformed ORC file %s. Invalid file size %s", orcDataSource, size);
}
// Read the tail of the file
byte[] buffer = new byte[Ints.checkedCast(min(size, EXPECTED_FOOTER_SIZE))];
orcDataSource.readFully(size - buffer.length, buffer);
// get length of PostScript - last byte of the file
int postScriptSize = buffer[buffer.length - SIZE_OF_BYTE] & 0xff;
// make sure this is an ORC file and not an RCFile or something else
verifyOrcFooter(orcDataSource, postScriptSize, buffer);
// decode the post script
int postScriptOffset = buffer.length - SIZE_OF_BYTE - postScriptSize;
PostScript postScript = metadataReader.readPostScript(buffer, postScriptOffset, postScriptSize);
// verify this is a supported version
checkOrcVersion(orcDataSource, postScript.getVersion());
// check compression codec is supported
this.compressionKind = postScript.getCompression();
this.bufferSize = Ints.checkedCast(postScript.getCompressionBlockSize());
int footerSize = Ints.checkedCast(postScript.getFooterLength());
int metadataSize = Ints.checkedCast(postScript.getMetadataLength());
// check if extra bytes need to be read
Slice completeFooterSlice;
int completeFooterSize = footerSize + metadataSize + postScriptSize + SIZE_OF_BYTE;
if (completeFooterSize > buffer.length) {
// allocate a new buffer large enough for the complete footer
byte[] newBuffer = new byte[completeFooterSize];
completeFooterSlice = Slices.wrappedBuffer(newBuffer);
// initial read was not large enough, so read missing section
orcDataSource.readFully(size - completeFooterSize, newBuffer, 0, completeFooterSize - buffer.length);
// copy already read bytes into the new buffer
completeFooterSlice.setBytes(completeFooterSize - buffer.length, buffer);
}
else {
// footer is already in the bytes in buffer, just adjust position, length
completeFooterSlice = Slices.wrappedBuffer(buffer, buffer.length - completeFooterSize, completeFooterSize);
}
// read metadata
Slice metadataSlice = completeFooterSlice.slice(0, metadataSize);
try (InputStream metadataInputStream = new OrcInputStream(orcDataSource.toString(), metadataSlice.getInput(), compressionKind, bufferSize, new AggregatedMemoryContext())) {
this.metadata = metadataReader.readMetadata(metadataInputStream);
}
// read footer
Slice footerSlice = completeFooterSlice.slice(metadataSize, footerSize);
try (InputStream footerInputStream = new OrcInputStream(orcDataSource.toString(), footerSlice.getInput(), compressionKind, bufferSize, new AggregatedMemoryContext())) {
this.footer = metadataReader.readFooter(footerInputStream);
}
}