From dev-return-2430-archive-asf-public=cust-asf.ponee.io@orc.apache.org Thu Jul 12 23:51:10 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 E568118078A for ; Thu, 12 Jul 2018 23:51:08 +0200 (CEST) Received: (qmail 35295 invoked by uid 500); 12 Jul 2018 21:51:07 -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 35068 invoked by uid 99); 12 Jul 2018 21:51:07 -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; Thu, 12 Jul 2018 21:51:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AF5F7DFC42; Thu, 12 Jul 2018 21:51:06 +0000 (UTC) From: prasanthj 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: <20180712215106.AF5F7DFC42@git1-us-west.apache.org> Date: Thu, 12 Jul 2018 21:51:06 +0000 (UTC) Github user prasanthj commented on a diff in the pull request: https://github.com/apache/orc/pull/278#discussion_r202144150 --- 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 -- Could you leave a comment as in why positioning is done this way? Looks like this is when 2 diskranges overlap. ---