From c636b3798f368ebfdd6fed7839e24f2072746e51 Mon Sep 17 00:00:00 2001 From: "Adrian T. Co" Date: Tue, 7 Nov 2006 21:00:46 +0000 Subject: [PATCH] Added test case to test resizing of internal buffer of DataByteArrayOutputStream. Fix bug during resizing of internal buffer of DataByteArrayOutputStream. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@472258 13f79535-47bb-0310-9956-ffa450edef68 --- .../util/DataByteArrayOutputStream.java | 14 +-- .../util/DataByteArrayOutputStreamTest.java | 101 ++++++++++++++++++ 2 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java index a90d0fb6e5..fbbab73d0c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java @@ -138,29 +138,29 @@ public final class DataByteArrayOutputStream extends OutputStream implements Dat public void writeBoolean(boolean v){ - ensureEnoughBuffer(1); + ensureEnoughBuffer(pos + 1); buf[pos++]=(byte) (v?1:0); } public void writeByte(int v){ - ensureEnoughBuffer(1); + ensureEnoughBuffer(pos + 1); buf[pos++]=(byte) (v>>>0); } public void writeShort(int v){ - ensureEnoughBuffer(2); + ensureEnoughBuffer(pos + 2); buf[pos++]=(byte) (v>>>8); buf[pos++]=(byte) (v>>>0); } public void writeChar(int v){ - ensureEnoughBuffer(2); + ensureEnoughBuffer(pos + 2); buf[pos++]=(byte) (v>>>8); buf[pos++]=(byte) (v>>>0); } public void writeInt(int v){ - ensureEnoughBuffer(4); + ensureEnoughBuffer(pos + 4); buf[pos++]=(byte) (v>>>24); buf[pos++]=(byte) (v>>>16); buf[pos++]=(byte) (v>>>8); @@ -168,7 +168,7 @@ public final class DataByteArrayOutputStream extends OutputStream implements Dat } public void writeLong(long v){ - ensureEnoughBuffer(8); + ensureEnoughBuffer(pos + 8); buf[pos++]=(byte) (v>>>56); buf[pos++]=(byte) (v>>>48); buf[pos++]=(byte) (v>>>40); @@ -219,7 +219,7 @@ public final class DataByteArrayOutputStream extends OutputStream implements Dat } if(encodedsize>65535) throw new UTFDataFormatException("encoded string too long: "+encodedsize+" bytes"); - ensureEnoughBuffer(encodedsize+2); + ensureEnoughBuffer(pos + encodedsize+2); writeShort(encodedsize); int i=0; for(i=0;i