Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CDE8C9F6B for ; Sat, 17 Mar 2012 17:30:01 +0000 (UTC) Received: (qmail 31453 invoked by uid 500); 17 Mar 2012 17:30:01 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 31381 invoked by uid 500); 17 Mar 2012 17:30:01 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 31372 invoked by uid 99); 17 Mar 2012 17:30:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Mar 2012 17:30:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Mar 2012 17:29:58 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id B8BD225E33 for ; Sat, 17 Mar 2012 17:29:37 +0000 (UTC) Date: Sat, 17 Mar 2012 17:29:37 +0000 (UTC) From: "Thomas Neidhart (Commented) (JIRA)" To: issues@commons.apache.org Message-ID: <1077221860.28319.1332005377758.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <590032359.12328.1317038366306.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CODEC-130) Base64InputStream.skip skips underlying stream, not output MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CODEC-130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13232023#comment-13232023 ] Thomas Neidhart commented on CODEC-130: --------------------------------------- My example was maybe not so clear, but yes that's basically what I think happens when skipping the underlying stream. In case you have a 1:1 mapping (1 byte in the underlying stream refers to 1 byte in the filtered stream), it does not matter. For compressing or encoding streams this may be different, so the skip method has to be adjusted imho. After looking at the code of InflaterInputStream, I think we can do quite the same here (and check also other filtered input streams). > Base64InputStream.skip skips underlying stream, not output > ---------------------------------------------------------- > > Key: CODEC-130 > URL: https://issues.apache.org/jira/browse/CODEC-130 > Project: Commons Codec > Issue Type: Bug > Affects Versions: 1.5 > Reporter: James Pickering > Priority: Minor > Attachments: base64snippet.java > > > Base64InputStream.skip() skips within underlying stream, leading to unexpected behaviour. > The following code will reproduce the issue: > @Test > public void testSkip() throws Throwable { > InputStream ins = > new ByteArrayInputStream("AAAA////".getBytes("ISO-8859-1"));//should decode to {0, 0, 0, 255, 255, 255} > Base64InputStream instance = new Base64InputStream(ins); > assertEquals(3L, instance.skip(3L)); //should skip 3 decoded characters, or 4 encoded characters > assertEquals(255, instance.read()); //Currently returns 3, as it is decoding "A/", not "//" > } > The following code, if added to Base64InputStream, or (BaseNCodecInputStream in the dev build) would resolve the issue: > @Override > public long skip(long n) throws IOException { > //delegate to read() > long bytesRead = 0; > while ((bytesRead < n) && (read() != -1)) { > bytesRead++; > } > return bytesRead; > } > More efficient code may be possible. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira