本文整理了Java中io.airlift.slice.Slice.setBytes()
方法的一些代码示例,展示了Slice.setBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.setBytes()
方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:setBytes
[英]Transfers data from the specified slice into this buffer starting at the specified absolute index.
[中]从指定的绝对索引开始,将数据从指定的片传输到此缓冲区。
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(InputStream in, int length)
throws IOException
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, in, batch);
bufferPosition += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(InputStream in, int length)
throws IOException
{
while (length > 0) {
int batch = ensureBatchSize(length);
slice.setBytes(bufferPosition, in, batch);
bufferPosition += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(Slice source, int sourceIndex, int length)
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, source, sourceIndex, batch);
bufferPosition += batch;
sourceIndex += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(Slice source, int sourceIndex, int length)
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, source, sourceIndex, batch);
bufferPosition += batch;
sourceIndex += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(InputStream in, int length)
throws IOException
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, in, batch);
bufferPosition += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(InputStream in, int length)
throws IOException
{
while (length > 0) {
int batch = ensureBatchSize(length);
slice.setBytes(bufferPosition, in, batch);
bufferPosition += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(byte[] source, int sourceIndex, int length)
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, source, sourceIndex, batch);
bufferPosition += batch;
sourceIndex += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(byte[] source, int sourceIndex, int length)
{
while (length > 0) {
int batch = tryEnsureBatchSize(length);
slice.setBytes(bufferPosition, source, sourceIndex, batch);
bufferPosition += batch;
sourceIndex += batch;
length -= batch;
}
}
代码示例来源:origin: prestodb/presto
public static Slice pack(BigInteger unscaledValue, Slice result)
{
pack(0, 0, false, result);
byte[] bytes = unscaledValue.abs().toByteArray();
if (bytes.length > UNSCALED_DECIMAL_128_SLICE_LENGTH
|| (bytes.length == UNSCALED_DECIMAL_128_SLICE_LENGTH && (bytes[0] & SIGN_BYTE_MASK) != 0)) {
throwOverflowException();
}
// convert to little-endian order
reverse(bytes);
result.setBytes(0, bytes);
if (unscaledValue.signum() < 0) {
setNegative(result, true);
}
throwIfOverflows(result);
return result;
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(Slice source, int sourceIndex, int length)
{
if (length >= CHUNK_SIZE) {
if (bufferPosition > 0) {
// fill up the current buffer
int flushLength = getFreeBufferLength();
slice.setBytes(bufferPosition, source, sourceIndex, flushLength);
bufferPosition = CHUNK_SIZE;
flushBufferToOutputStream();
sourceIndex += flushLength;
length -= flushLength;
}
// line up the chunk to chunk size and flush directly to OutputStream
while (length >= CHUNK_SIZE) {
writeToOutputStream(source, sourceIndex, CHUNK_SIZE);
sourceIndex += CHUNK_SIZE;
length -= CHUNK_SIZE;
bufferOffset += CHUNK_SIZE;
}
}
if (length > 0) {
// buffer the remaining data
ensureWritableBytes(length);
slice.setBytes(bufferPosition, source, sourceIndex, length);
bufferPosition += length;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(byte[] source, int sourceIndex, int length)
{
if (length >= CHUNK_SIZE) {
if (bufferPosition > 0) {
// fill up the current buffer
int flushLength = getFreeBufferLength();
slice.setBytes(bufferPosition, source, sourceIndex, flushLength);
bufferPosition = CHUNK_SIZE;
flushBufferToOutputStream();
sourceIndex += flushLength;
length -= flushLength;
}
// line up the chunk to chunk size and flush directly to OutputStream
while (length >= CHUNK_SIZE) {
writeToOutputStream(source, sourceIndex, CHUNK_SIZE);
sourceIndex += CHUNK_SIZE;
length -= CHUNK_SIZE;
bufferOffset += CHUNK_SIZE;
}
}
if (length > 0) {
// buffer the remaining data
ensureWritableBytes(length);
slice.setBytes(bufferPosition, source, sourceIndex, length);
bufferPosition += length;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(byte[] source, int sourceIndex, int length)
{
// Write huge chunks direct to OutputStream
if (length >= DIRECT_FLUSH_SIZE) {
// todo fill buffer before flushing
flushBufferToOutputStream();
writeDirectlyToOutputStream(source, sourceIndex, length);
bufferOffset += length;
}
else {
ensureWritableBytes(length);
slice.setBytes(bufferPosition, source, sourceIndex, length);
bufferPosition += length;
}
}
代码示例来源:origin: prestodb/presto
@Override
public void decompress(Slice compressed, Slice uncompressed)
throws RcFileCorruptionException
{
checkState(!destroyed, "Codec has been destroyed");
decompressor.reset();
try (CompressionInputStream decompressorStream = codec.createInputStream(compressed.getInput(), decompressor)) {
uncompressed.setBytes(0, decompressorStream, uncompressed.length());
}
catch (IndexOutOfBoundsException | IOException e) {
throw new RcFileCorruptionException(e, "Compressed stream is truncated");
}
}
代码示例来源:origin: prestodb/presto
@Override
public void decompress(Slice compressed, Slice uncompressed)
throws RcFileCorruptionException
{
try (CompressionInputStream decompressorStream = codec.createInputStream(compressed.getInput())) {
uncompressed.setBytes(0, decompressorStream, uncompressed.length());
}
catch (IndexOutOfBoundsException | IOException e) {
throw new RcFileCorruptionException(e, "Compressed stream is truncated");
}
}
代码示例来源:origin: prestodb/presto
public static byte[] serializeModels(Model... models)
{
List<byte[]> serializedModels = new ArrayList<>();
int size = SIZE_OF_INT + SIZE_OF_INT * models.length;
for (Model model : models) {
byte[] bytes = serialize(model).getBytes();
size += bytes.length;
serializedModels.add(bytes);
}
Slice slice = Slices.allocate(size);
slice.setInt(0, models.length);
for (int i = 0; i < models.length; i++) {
slice.setInt(SIZE_OF_INT * (i + 1), serializedModels.get(i).length);
}
int offset = SIZE_OF_INT + SIZE_OF_INT * models.length;
for (byte[] bytes : serializedModels) {
slice.setBytes(offset, bytes);
offset += bytes.length;
}
return slice.getBytes();
}
代码示例来源:origin: prestodb/presto
buffer.setBytes(startPointOfExistingText, inputSlice);
buffer.setBytes(byteIndex, padSlice);
byteIndex += padSlice.length();
buffer.setBytes(byteIndex, padSlice.getBytes(0, paddingOffset + fillLength - byteIndex));
代码示例来源:origin: prestodb/presto
public static Slice padSpaces(Slice slice, int length)
{
int textLength = countCodePoints(slice);
// if our string is bigger than requested then truncate
if (textLength > length) {
throw new IllegalArgumentException("pad length is smaller than slice length");
}
// if our target length is the same as our string then return our string
if (textLength == length) {
return slice;
}
// preallocate the result
int bufferSize = slice.length() + length - textLength;
Slice buffer = Slices.allocate(bufferSize);
// fill in the existing string
buffer.setBytes(0, slice);
// fill padding spaces
for (int i = slice.length(); i < bufferSize; ++i) {
buffer.setByte(i, ' ');
}
return buffer;
}
代码示例来源:origin: prestodb/presto
@Override
public void writeBytes(Slice source, int sourceIndex, int length)
{
// Write huge chunks direct to OutputStream
if (length >= DIRECT_FLUSH_SIZE) {
flushBufferToOutputStream();
writeDirectlyToOutputStream((byte[]) source.getBase(), sourceIndex + (int) (source.getAddress() - ARRAY_BYTE_BASE_OFFSET), length);
bufferOffset += length;
}
else {
ensureWritableBytes(length);
slice.setBytes(bufferPosition, source, sourceIndex, length);
bufferPosition += length;
}
}
代码示例来源:origin: prestodb/presto
@Description("concatenates given character strings")
@ScalarFunction
@LiteralParameters({"x", "y", "u"})
@Constraint(variable = "u", expression = "x + y")
@SqlType("char(u)")
public static Slice concat(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice left, @SqlType("char(y)") Slice right)
{
int rightLength = right.length();
if (rightLength == 0) {
return left;
}
Slice paddedLeft = padSpaces(left, x.intValue());
int leftLength = paddedLeft.length();
Slice result = Slices.allocate(leftLength + rightLength);
result.setBytes(0, paddedLeft);
result.setBytes(leftLength, right);
return result;
}
}
代码示例来源:origin: prestodb/presto
private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
{
Slice slice = Slices.allocate((int) file.length());
try (InputStream in = new FileInputStream(file)) {
slice.setBytes(0, in, slice.length());
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
List<Long> syncPositionsBruteForce = new ArrayList<>();
Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
sync.setInt(0, -1);
sync.setBytes(SIZE_OF_INT, recordReader.getSync());
long syncPosition = 0;
while (syncPosition >= 0) {
syncPosition = slice.indexOf(sync, (int) syncPosition);
if (syncPosition > 0) {
syncPositionsBruteForce.add(syncPosition);
syncPosition++;
}
}
return syncPositionsBruteForce;
}
内容来源于网络,如有侵权,请联系作者删除!