Github user prasanthj commented on a diff in the pull request:

    https://github.com/apache/orc/pull/278#discussion_r202189630
  
    --- Diff: java/core/src/java/org/apache/orc/impl/InStream.java ---
    @@ -401,84 +596,149 @@ private String rangeString() {
         @Override
         public String toString() {
           return "compressed stream " + name + " position: " + currentOffset +
    -          " length: " + length + " range: " + currentRange +
    -          " offset: " + (compressed == null ? 0 : compressed.position()) + 
" limit: " + (compressed == null ? 0 : compressed.limit()) +
    +          " length: " + length + " range: " + getRangeNumber(bytes, 
currentRange) +
    +          " offset: " + (compressed == null ? 0 : compressed.position()) +
    +          " limit: " + (compressed == null ? 0 : compressed.limit()) +
               rangeString() +
               (uncompressed == null ? "" :
                   " uncompressed: " + uncompressed.position() + " to " +
                       uncompressed.limit());
         }
       }
     
    +  private static class EncryptedCompressedStream extends CompressedStream {
    +    private final EncryptionState encrypt;
    +
    +    public EncryptedCompressedStream(String name,
    +                                     DiskRangeList input,
    +                                     long length,
    +                                     StreamOptions options) {
    +      super(name, length, options);
    +      encrypt = new EncryptionState(name, options);
    +      reset(input, length);
    +    }
    +
    +    @Override
    +    protected void setCurrent(DiskRangeList newRange, boolean isJump) {
    +      currentRange = newRange;
    +      if (newRange != null) {
    +        if (isJump) {
    +          encrypt.changeIv(newRange.getOffset());
    +        }
    +        compressed = encrypt.decrypt(newRange);
    +        compressed.position((int) (currentOffset - newRange.getOffset()));
    +      }
    +    }
    +
    +    @Override
    +    public void close() {
    +      super.close();
    +      encrypt.close();
    +    }
    +
    +    @Override
    +    public String toString() {
    +      return "encrypted " + super.toString();
    +    }
    +  }
    +
       public abstract void seek(PositionProvider index) throws IOException;
     
    +  public static class StreamOptions implements Cloneable {
    +    private CompressionCodec codec;
    +    private int bufferSize;
    +    private EncryptionAlgorithm algorithm;
    +    private Key key;
    +    private byte[] iv;
    +
    +    public StreamOptions withCodec(CompressionCodec value) {
    +      this.codec = value;
    +      return this;
    +    }
    +
    +    public StreamOptions withBufferSize(int value) {
    +      bufferSize = value;
    +      return this;
    +    }
    +
    +    public StreamOptions withEncryption(EncryptionAlgorithm algorithm,
    +                                        Key key,
    +                                        byte[] iv) {
    +      this.algorithm = algorithm;
    +      this.key = key;
    +      this.iv = iv;
    +      return this;
    +    }
    +
    +    public CompressionCodec getCodec() {
    +      return codec;
    +    }
    +
    +    @Override
    +    public StreamOptions clone() {
    +      try {
    +        StreamOptions clone = (StreamOptions) super.clone();
    +        if (clone.codec != null) {
    +          // Make sure we don't share the same codec between two readers.
    +          clone.codec = OrcCodecPool.getCodec(codec.getKind());
    +        }
    +        return clone;
    --- End diff --
    
    why is this clone required? incomplete clone anyways


---

Reply via email to