orc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omalley <...@git.apache.org>
Subject [GitHub] orc pull request #278: ORC-251: Extend InStream and OutStream to support enc...
Date Fri, 13 Jul 2018 18:06:10 GMT
Github user omalley commented on a diff in the pull request:

    https://github.com/apache/orc/pull/278#discussion_r202430812
  
    --- Diff: java/core/src/java/org/apache/orc/impl/InStream.java ---
    @@ -55,112 +60,137 @@ public long getStreamLength() {
       @Override
       public abstract void close();
     
    +  static int getRangeNumber(DiskRangeList list, DiskRangeList current) {
    +    int result = 0;
    +    DiskRangeList range = list;
    +    while (range != null && range != current) {
    +      result += 1;
    +      range = range.next;
    +    }
    +    return result;
    +  }
    +
    +  /**
    +   * Implements a stream over an uncompressed stream.
    +   */
       public static class UncompressedStream extends InStream {
    -    private List<DiskRange> bytes;
    +    private DiskRangeList bytes;
         private long length;
         protected long currentOffset;
    -    private ByteBuffer range;
    -    private int currentRange;
    +    protected ByteBuffer decrypted;
    +    protected DiskRangeList currentRange;
    +
    +    /**
    +     * Create the stream without calling reset on it.
    +     * This is used for the subclass that needs to do more setup.
    +     * @param name name of the stream
    +     * @param length the number of bytes for the stream
    +     */
    +    public UncompressedStream(String name, long length) {
    +      super(name, length);
    +    }
     
    -    public UncompressedStream(String name, List<DiskRange> input, long length)
{
    +    public UncompressedStream(String name,
    +                              DiskRangeList input,
    +                              long length) {
           super(name, length);
           reset(input, length);
         }
     
    -    protected void reset(List<DiskRange> input, long length) {
    +    protected void reset(DiskRangeList input, long length) {
           this.bytes = input;
           this.length = length;
    -      currentRange = 0;
    -      currentOffset = 0;
    -      range = null;
    +      currentOffset = input == null ? 0 : input.getOffset();
    +      setCurrent(input, true);
         }
     
         @Override
         public int read() {
    -      if (range == null || range.remaining() == 0) {
    +      if (decrypted == null || decrypted.remaining() == 0) {
             if (currentOffset == length) {
               return -1;
             }
    -        seek(currentOffset);
    +        setCurrent(currentRange.next, false);
           }
           currentOffset += 1;
    -      return 0xff & range.get();
    +      return 0xff & decrypted.get();
    +    }
    +
    +    protected void setCurrent(DiskRangeList newRange, boolean isJump) {
    +      currentRange = newRange;
    +      if (newRange != null) {
    +        decrypted = newRange.getData().slice();
    +        decrypted.position((int) (currentOffset - newRange.getOffset()));
    --- End diff --
    
    No, it is moving the ByteBuffer position to the correct spot so that it matches currentOffset,
which is relative to the stream.


---

Mime
View raw message