[ 
https://issues.apache.org/jira/browse/ORC-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16543719#comment-16543719
 ] 

ASF GitHub Bot commented on ORC-251:
------------------------------------

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

    https://github.com/apache/orc/pull/278#discussion_r202473870
  
    --- 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 --
    
    *sigh* It is Cloneable, because it is used as a field in DefaultDataReader. 
The clone is correct, I believe. We really need a better solution for 
CompressionCodec than the current Cloneable and CompressionCodecPool mess. We 
need to remove the compression parameters out of Codec and then they are 
completely stateless again and can be trivially pooled.


> Modify InStream and OutStream to optionally encrypt data
> --------------------------------------------------------
>
>                 Key: ORC-251
>                 URL: https://issues.apache.org/jira/browse/ORC-251
>             Project: ORC
>          Issue Type: Sub-task
>            Reporter: Owen O'Malley
>            Assignee: Owen O'Malley
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to