本文整理汇总了Java中io.airlift.slice.Slice.setBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.setBytes方法的具体用法?Java Slice.setBytes怎么用?Java Slice.setBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.airlift.slice.Slice
的用法示例。
在下文中一共展示了Slice.setBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: concatSlices
import io.airlift.slice.Slice; //导入方法依赖的package包/类
@VisibleForTesting
static Slice concatSlices(Slice slice1, Slice slice2)
{
Slice slice = Slices.allocate(slice1.length() + slice2.length());
slice.setBytes(0, slice1.getBytes());
slice.setBytes(slice1.length(), slice2.getBytes());
return slice;
}
示例2: serialize
import io.airlift.slice.Slice; //导入方法依赖的package包/类
/**
* Serializes the model using the following format
* int: format version
* byte[32]: SHA256 hash of all following data
* int: id of algorithm
* int: length of hyperparameters section
* byte[]: hyperparameters (currently not used)
* long: length of data section
* byte[]: model data
*
* note: all multibyte values are in little endian
*/
public static Slice serialize(Model model)
{
requireNonNull(model, "model is null");
Integer id = MODEL_SERIALIZATION_IDS.get(model.getClass());
requireNonNull(id, "id is null");
int size = HYPERPARAMETERS_OFFSET;
// hyperparameters aren't implemented yet
byte[] hyperparameters = new byte[0];
size += hyperparameters.length;
int dataLengthOffset = size;
size += SIZE_OF_LONG;
int dataOffset = size;
byte[] data = model.getSerializedData();
size += data.length;
Slice slice = Slices.allocate(size);
slice.setInt(VERSION_OFFSET, CURRENT_FORMAT_VERSION);
slice.setInt(ALGORITHM_OFFSET, id);
slice.setInt(HYPERPARAMETER_LENGTH_OFFSET, hyperparameters.length);
slice.setBytes(HYPERPARAMETERS_OFFSET, hyperparameters);
slice.setLong(dataLengthOffset, data.length);
slice.setBytes(dataOffset, data);
byte[] modelHash = Hashing.sha256().hashBytes(slice.getBytes(ALGORITHM_OFFSET, slice.length() - ALGORITHM_OFFSET)).asBytes();
checkState(modelHash.length == 32, "sha256 hash code expected to be 32 bytes");
slice.setBytes(HASH_OFFSET, modelHash);
return slice;
}
示例3: 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);
}
}