From dev-return-2440-archive-asf-public=cust-asf.ponee.io@orc.apache.org Fri Jul 13 20:07:33 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 85A80180676 for ; Fri, 13 Jul 2018 20:07:32 +0200 (CEST) Received: (qmail 17772 invoked by uid 500); 13 Jul 2018 18:07:31 -0000 Mailing-List: contact dev-help@orc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@orc.apache.org Delivered-To: mailing list dev@orc.apache.org Received: (qmail 17759 invoked by uid 99); 13 Jul 2018 18:07:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jul 2018 18:07:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D5775DFAE2; Fri, 13 Jul 2018 18:07:30 +0000 (UTC) From: omalley To: dev@orc.apache.org Reply-To: dev@orc.apache.org References: In-Reply-To: Subject: [GitHub] orc pull request #278: ORC-251: Extend InStream and OutStream to support enc... Content-Type: text/plain Message-Id: <20180713180730.D5775DFAE2@git1-us-west.apache.org> Date: Fri, 13 Jul 2018 18:07:30 +0000 (UTC) Github user omalley commented on a diff in the pull request: https://github.com/apache/orc/pull/278#discussion_r202431172 --- 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 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 input, long length) { + public UncompressedStream(String name, + DiskRangeList input, + long length) { super(name, length); reset(input, length); } - protected void reset(List 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 -- But I'll add a comment to the code. ---