Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 803295FA2 for ; Thu, 12 May 2011 20:06:31 +0000 (UTC) Received: (qmail 56287 invoked by uid 500); 12 May 2011 20:06:31 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 56247 invoked by uid 500); 12 May 2011 20:06:31 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 56240 invoked by uid 99); 12 May 2011 20:06:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 May 2011 20:06:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 May 2011 20:06:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AC24223888BD; Thu, 12 May 2011 20:06:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1102448 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java Date: Thu, 12 May 2011 20:06:06 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110512200606.AC24223888BD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Thu May 12 20:06:06 2011 New Revision: 1102448 URL: http://svn.apache.org/viewvc?rev=1102448&view=rev Log: The NPOIFS mini stream blocks need to be writable, correct that and add some tests Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java?rev=1102448&r1=1102447&r2=1102448&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java (original) +++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java Thu May 12 20:06:06 2011 @@ -69,16 +69,13 @@ public class NPOIFSMiniStore extends Blo it.next(); } ByteBuffer dataBlock = it.next(); - - // Our blocks are small, so duplicating it is fine - byte[] data = new byte[POIFSConstants.SMALL_BLOCK_SIZE]; + + // Position ourselves, and take a slice dataBlock.position( dataBlock.position() + bigBlockOffset ); - dataBlock.get(data, 0, data.length); - - // Return a ByteBuffer on this - ByteBuffer miniBuffer = ByteBuffer.wrap(data); + ByteBuffer miniBuffer = dataBlock.slice(); + miniBuffer.limit(POIFSConstants.SMALL_BLOCK_SIZE); return miniBuffer; } Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java?rev=1102448&r1=1102447&r2=1102448&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java Thu May 12 20:06:06 2011 @@ -603,7 +603,135 @@ public final class TestNPOIFSStream exte */ public void testWriteMiniStreams() throws Exception { NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); + NPOIFSMiniStore ministore = fs.getMiniStore(); + NPOIFSStream stream = new NPOIFSStream(ministore, 178); + // 178 -> 179 -> 180 -> end + assertEquals(179, ministore.getNextBlock(178)); + assertEquals(180, ministore.getNextBlock(179)); + assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180)); + + + // Try writing 3 full blocks worth + byte[] data = new byte[64*3]; + for(int i=0; i it = stream.getBlockIterator(); + ByteBuffer b178 = it.next(); + ByteBuffer b179 = it.next(); + ByteBuffer b180 = it.next(); + assertEquals(false, it.hasNext()); + + assertEquals((byte)0x00, b178.get()); + assertEquals((byte)0x01, b178.get()); + assertEquals((byte)0x40, b179.get()); + assertEquals((byte)0x41, b179.get()); + assertEquals((byte)0x80, b180.get()); + assertEquals((byte)0x81, b180.get()); + + + // Try writing just into 3 blocks worth + data = new byte[64*2 + 12]; + for(int i=0; i