io.airlift.slice.Slice.setBytes()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中io.airlift.slice.Slice.setBytes()方法的一些代码示例,展示了Slice.setBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.setBytes()方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:setBytes

Slice.setBytes介绍

[英]Transfers data from the specified slice into this buffer starting at the specified absolute index.
[中]从指定的绝对索引开始,将数据从指定的片传输到此缓冲区。

代码示例

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(InputStream in, int length)
  3. throws IOException
  4. {
  5. while (length > 0) {
  6. int batch = tryEnsureBatchSize(length);
  7. slice.setBytes(bufferPosition, in, batch);
  8. bufferPosition += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(InputStream in, int length)
  3. throws IOException
  4. {
  5. while (length > 0) {
  6. int batch = ensureBatchSize(length);
  7. slice.setBytes(bufferPosition, in, batch);
  8. bufferPosition += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(Slice source, int sourceIndex, int length)
  3. {
  4. while (length > 0) {
  5. int batch = tryEnsureBatchSize(length);
  6. slice.setBytes(bufferPosition, source, sourceIndex, batch);
  7. bufferPosition += batch;
  8. sourceIndex += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(Slice source, int sourceIndex, int length)
  3. {
  4. while (length > 0) {
  5. int batch = tryEnsureBatchSize(length);
  6. slice.setBytes(bufferPosition, source, sourceIndex, batch);
  7. bufferPosition += batch;
  8. sourceIndex += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(InputStream in, int length)
  3. throws IOException
  4. {
  5. while (length > 0) {
  6. int batch = tryEnsureBatchSize(length);
  7. slice.setBytes(bufferPosition, in, batch);
  8. bufferPosition += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(InputStream in, int length)
  3. throws IOException
  4. {
  5. while (length > 0) {
  6. int batch = ensureBatchSize(length);
  7. slice.setBytes(bufferPosition, in, batch);
  8. bufferPosition += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(byte[] source, int sourceIndex, int length)
  3. {
  4. while (length > 0) {
  5. int batch = tryEnsureBatchSize(length);
  6. slice.setBytes(bufferPosition, source, sourceIndex, batch);
  7. bufferPosition += batch;
  8. sourceIndex += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(byte[] source, int sourceIndex, int length)
  3. {
  4. while (length > 0) {
  5. int batch = tryEnsureBatchSize(length);
  6. slice.setBytes(bufferPosition, source, sourceIndex, batch);
  7. bufferPosition += batch;
  8. sourceIndex += batch;
  9. length -= batch;
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. public static Slice pack(BigInteger unscaledValue, Slice result)
  2. {
  3. pack(0, 0, false, result);
  4. byte[] bytes = unscaledValue.abs().toByteArray();
  5. if (bytes.length > UNSCALED_DECIMAL_128_SLICE_LENGTH
  6. || (bytes.length == UNSCALED_DECIMAL_128_SLICE_LENGTH && (bytes[0] & SIGN_BYTE_MASK) != 0)) {
  7. throwOverflowException();
  8. }
  9. // convert to little-endian order
  10. reverse(bytes);
  11. result.setBytes(0, bytes);
  12. if (unscaledValue.signum() < 0) {
  13. setNegative(result, true);
  14. }
  15. throwIfOverflows(result);
  16. return result;
  17. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(Slice source, int sourceIndex, int length)
  3. {
  4. if (length >= CHUNK_SIZE) {
  5. if (bufferPosition > 0) {
  6. // fill up the current buffer
  7. int flushLength = getFreeBufferLength();
  8. slice.setBytes(bufferPosition, source, sourceIndex, flushLength);
  9. bufferPosition = CHUNK_SIZE;
  10. flushBufferToOutputStream();
  11. sourceIndex += flushLength;
  12. length -= flushLength;
  13. }
  14. // line up the chunk to chunk size and flush directly to OutputStream
  15. while (length >= CHUNK_SIZE) {
  16. writeToOutputStream(source, sourceIndex, CHUNK_SIZE);
  17. sourceIndex += CHUNK_SIZE;
  18. length -= CHUNK_SIZE;
  19. bufferOffset += CHUNK_SIZE;
  20. }
  21. }
  22. if (length > 0) {
  23. // buffer the remaining data
  24. ensureWritableBytes(length);
  25. slice.setBytes(bufferPosition, source, sourceIndex, length);
  26. bufferPosition += length;
  27. }
  28. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(byte[] source, int sourceIndex, int length)
  3. {
  4. if (length >= CHUNK_SIZE) {
  5. if (bufferPosition > 0) {
  6. // fill up the current buffer
  7. int flushLength = getFreeBufferLength();
  8. slice.setBytes(bufferPosition, source, sourceIndex, flushLength);
  9. bufferPosition = CHUNK_SIZE;
  10. flushBufferToOutputStream();
  11. sourceIndex += flushLength;
  12. length -= flushLength;
  13. }
  14. // line up the chunk to chunk size and flush directly to OutputStream
  15. while (length >= CHUNK_SIZE) {
  16. writeToOutputStream(source, sourceIndex, CHUNK_SIZE);
  17. sourceIndex += CHUNK_SIZE;
  18. length -= CHUNK_SIZE;
  19. bufferOffset += CHUNK_SIZE;
  20. }
  21. }
  22. if (length > 0) {
  23. // buffer the remaining data
  24. ensureWritableBytes(length);
  25. slice.setBytes(bufferPosition, source, sourceIndex, length);
  26. bufferPosition += length;
  27. }
  28. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(byte[] source, int sourceIndex, int length)
  3. {
  4. // Write huge chunks direct to OutputStream
  5. if (length >= DIRECT_FLUSH_SIZE) {
  6. // todo fill buffer before flushing
  7. flushBufferToOutputStream();
  8. writeDirectlyToOutputStream(source, sourceIndex, length);
  9. bufferOffset += length;
  10. }
  11. else {
  12. ensureWritableBytes(length);
  13. slice.setBytes(bufferPosition, source, sourceIndex, length);
  14. bufferPosition += length;
  15. }
  16. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void decompress(Slice compressed, Slice uncompressed)
  3. throws RcFileCorruptionException
  4. {
  5. checkState(!destroyed, "Codec has been destroyed");
  6. decompressor.reset();
  7. try (CompressionInputStream decompressorStream = codec.createInputStream(compressed.getInput(), decompressor)) {
  8. uncompressed.setBytes(0, decompressorStream, uncompressed.length());
  9. }
  10. catch (IndexOutOfBoundsException | IOException e) {
  11. throw new RcFileCorruptionException(e, "Compressed stream is truncated");
  12. }
  13. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void decompress(Slice compressed, Slice uncompressed)
  3. throws RcFileCorruptionException
  4. {
  5. try (CompressionInputStream decompressorStream = codec.createInputStream(compressed.getInput())) {
  6. uncompressed.setBytes(0, decompressorStream, uncompressed.length());
  7. }
  8. catch (IndexOutOfBoundsException | IOException e) {
  9. throw new RcFileCorruptionException(e, "Compressed stream is truncated");
  10. }
  11. }

代码示例来源:origin: prestodb/presto

  1. public static byte[] serializeModels(Model... models)
  2. {
  3. List<byte[]> serializedModels = new ArrayList<>();
  4. int size = SIZE_OF_INT + SIZE_OF_INT * models.length;
  5. for (Model model : models) {
  6. byte[] bytes = serialize(model).getBytes();
  7. size += bytes.length;
  8. serializedModels.add(bytes);
  9. }
  10. Slice slice = Slices.allocate(size);
  11. slice.setInt(0, models.length);
  12. for (int i = 0; i < models.length; i++) {
  13. slice.setInt(SIZE_OF_INT * (i + 1), serializedModels.get(i).length);
  14. }
  15. int offset = SIZE_OF_INT + SIZE_OF_INT * models.length;
  16. for (byte[] bytes : serializedModels) {
  17. slice.setBytes(offset, bytes);
  18. offset += bytes.length;
  19. }
  20. return slice.getBytes();
  21. }

代码示例来源:origin: prestodb/presto

  1. buffer.setBytes(startPointOfExistingText, inputSlice);
  2. buffer.setBytes(byteIndex, padSlice);
  3. byteIndex += padSlice.length();
  4. buffer.setBytes(byteIndex, padSlice.getBytes(0, paddingOffset + fillLength - byteIndex));

代码示例来源:origin: prestodb/presto

  1. public static Slice padSpaces(Slice slice, int length)
  2. {
  3. int textLength = countCodePoints(slice);
  4. // if our string is bigger than requested then truncate
  5. if (textLength > length) {
  6. throw new IllegalArgumentException("pad length is smaller than slice length");
  7. }
  8. // if our target length is the same as our string then return our string
  9. if (textLength == length) {
  10. return slice;
  11. }
  12. // preallocate the result
  13. int bufferSize = slice.length() + length - textLength;
  14. Slice buffer = Slices.allocate(bufferSize);
  15. // fill in the existing string
  16. buffer.setBytes(0, slice);
  17. // fill padding spaces
  18. for (int i = slice.length(); i < bufferSize; ++i) {
  19. buffer.setByte(i, ' ');
  20. }
  21. return buffer;
  22. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeBytes(Slice source, int sourceIndex, int length)
  3. {
  4. // Write huge chunks direct to OutputStream
  5. if (length >= DIRECT_FLUSH_SIZE) {
  6. flushBufferToOutputStream();
  7. writeDirectlyToOutputStream((byte[]) source.getBase(), sourceIndex + (int) (source.getAddress() - ARRAY_BYTE_BASE_OFFSET), length);
  8. bufferOffset += length;
  9. }
  10. else {
  11. ensureWritableBytes(length);
  12. slice.setBytes(bufferPosition, source, sourceIndex, length);
  13. bufferPosition += length;
  14. }
  15. }

代码示例来源:origin: prestodb/presto

  1. @Description("concatenates given character strings")
  2. @ScalarFunction
  3. @LiteralParameters({"x", "y", "u"})
  4. @Constraint(variable = "u", expression = "x + y")
  5. @SqlType("char(u)")
  6. public static Slice concat(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice left, @SqlType("char(y)") Slice right)
  7. {
  8. int rightLength = right.length();
  9. if (rightLength == 0) {
  10. return left;
  11. }
  12. Slice paddedLeft = padSpaces(left, x.intValue());
  13. int leftLength = paddedLeft.length();
  14. Slice result = Slices.allocate(leftLength + rightLength);
  15. result.setBytes(0, paddedLeft);
  16. result.setBytes(leftLength, right);
  17. return result;
  18. }
  19. }

代码示例来源:origin: prestodb/presto

  1. private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
  2. {
  3. Slice slice = Slices.allocate((int) file.length());
  4. try (InputStream in = new FileInputStream(file)) {
  5. slice.setBytes(0, in, slice.length());
  6. }
  7. catch (IOException e) {
  8. throw new UncheckedIOException(e);
  9. }
  10. List<Long> syncPositionsBruteForce = new ArrayList<>();
  11. Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
  12. sync.setInt(0, -1);
  13. sync.setBytes(SIZE_OF_INT, recordReader.getSync());
  14. long syncPosition = 0;
  15. while (syncPosition >= 0) {
  16. syncPosition = slice.indexOf(sync, (int) syncPosition);
  17. if (syncPosition > 0) {
  18. syncPositionsBruteForce.add(syncPosition);
  19. syncPosition++;
  20. }
  21. }
  22. return syncPositionsBruteForce;
  23. }

相关文章