[jboss-cvs] JBoss Messaging SVN: r4422 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 10 10:21:36 EDT 2008
Author: jmesnil
Date: 2008-06-10 10:21:36 -0400 (Tue, 10 Jun 2008)
New Revision: 4422
Removed:
trunk/src/main/org/jboss/messaging/util/SafeUTF.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java
Log:
JBMESSAGING-379 - Split large messages into fragments
- removed SafeUTF, fix won't use streams anyway
Deleted: trunk/src/main/org/jboss/messaging/util/SafeUTF.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/SafeUTF.java 2008-06-10 14:11:52 UTC (rev 4421)
+++ trunk/src/main/org/jboss/messaging/util/SafeUTF.java 2008-06-10 14:21:36 UTC (rev 4422)
@@ -1,147 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.util;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- *
- * A SafeUTF
- *
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1174 $
- *
- * $Id: SafeUTF.java 1174 2006-08-02 14:14:32Z timfox $
- *
- * There is a "bug" in JDK1.4 / 1.5 DataOutputStream.writeUTF()
- * which means it does not work with Strings >= 64K serialized size.
- * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4806007
- *
- * We work around this by chunking larger strings into smaller pieces.
- *
- * Note we only support TextMessage and ObjectMessage bodies with serialized length >= 64K
- * We DO NOT support Strings written to BytesMessages or StreamMessages or written as keys or values
- * in MapMessages, or as String properties or other String fields having serialized length >= 64K
- * This is for performance reasons since there is an overhead in coping with large
- * Strings
- *
- */
-public class SafeUTF
-{
- //Default is 16K chunks
- private static final int CHUNK_SIZE = 16 * 1024;
-
- private static final byte NULL = 0;
-
- private static final byte NOT_NULL = 1;
-
- public static void safeWriteUTF(DataOutputStream out, String str) throws IOException
- {
- if (str == null)
- {
- out.writeByte(NULL);
- }
- else
- {
- int len = str.length();
-
- short numChunks;
-
- if (len == 0)
- {
- numChunks = 0;
- }
- else
- {
- numChunks = (short)(((len - 1) / CHUNK_SIZE) + 1);
- }
-
- out.writeByte(NOT_NULL);
-
- out.writeShort(numChunks);
-
- int i = 0;
- while (len > 0)
- {
- int beginCopy = i * CHUNK_SIZE;
-
- int endCopy = len <= CHUNK_SIZE ? beginCopy + len : beginCopy + CHUNK_SIZE;
-
- String theChunk = str.substring(beginCopy, endCopy);
-
- out.writeUTF(theChunk);
-
- len -= CHUNK_SIZE;
-
- i++;
- }
- }
- }
-
- public static String safeReadUTF(DataInputStream in) throws IOException
- {
- boolean isNull = in.readByte() == NULL;
-
- if (isNull)
- {
- return null;
- }
-
- short numChunks = in.readShort();
-
- int bufferSize = CHUNK_SIZE * numChunks;
-
- // special handling for single chunk
- if (numChunks == 1)
- {
- // The text size is likely to be much smaller than the chunkSize
- // so set bufferSize to the min of the input stream available
- // and the maximum buffer size. Since the input stream
- // available() can be <= 0 we check for that and default to
- // a small msg size of 256 bytes.
-
- int inSize = in.available();
-
- if (inSize <= 0)
- {
- inSize = 256;
- }
-
- bufferSize = Math.min(inSize, bufferSize);
- }
-
- StringBuffer buff = new StringBuffer(bufferSize);
-
- for (int i = 0; i < numChunks; i++)
- {
- String s = in.readUTF();
-
- buff.append(s);
- }
-
- return buff.toString();
- }
-
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java 2008-06-10 14:11:52 UTC (rev 4421)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java 2008-06-10 14:21:36 UTC (rev 4422)
@@ -1,152 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.tests.unit.core.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.util.SafeUTF;
-
-/**
- *
- * There is a bug in JDK1.3, 1.4 whereby writeUTF fails if more than 64K bytes are written
- * we need to work with all size of strings
- *
- * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4806007
- * http://jira.jboss.com/jira/browse/JBAS-2641
- *
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- *
- * @version $Revision: 1174 $
- */
-public class SafeUTFTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public SafeUTFTest(String name)
- {
- super(name);
- }
-
- // TestCase overrides -------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testSafeWriteReadUTFTest1() throws Exception
- {
- //Make sure we hit all the edge cases
- doTest("a", 10);
- doTest("ab", 10);
- doTest("abc", 10);
- doTest("abcd", 10);
- doTest("abcde", 10);
- doTest("abcdef", 10);
- doTest("abcdefg", 10);
- doTest("abcdefgh", 10);
- doTest("abcdefghi", 10);
- doTest("abcdefghij", 10);
- doTest("abcdefghijk", 10);
- doTest("abcdefghijkl", 10);
- doTest("abcdefghijklm", 10);
- doTest("abcdefghijklmn", 10);
- doTest("abcdefghijklmno", 10);
- doTest("abcdefghijklmnop", 10);
- doTest("abcdefghijklmnopq", 10);
- doTest("abcdefghijklmnopqr", 10);
- doTest("abcdefghijklmnopqrs", 10);
- doTest("abcdefghijklmnopqrst", 10);
- doTest("abcdefghijklmnopqrstu", 10);
- doTest("abcdefghijklmnopqrstuv", 10);
- doTest("abcdefghijklmnopqrstuvw", 10);
- doTest("abcdefghijklmnopqrstuvwx", 10);
- doTest("abcdefghijklmnopqrstuvwxy", 10);
- doTest("abcdefghijklmnopqrstuvwxyz", 10);
-
- //Need to work with null too
- doTest(null, 10);
-
- }
-
- protected void doTest(String s, int chunkSize) throws Exception
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- DataOutputStream dos = new DataOutputStream(bos);
-
- SafeUTF.safeWriteUTF(dos, s);
-
- dos.close();
-
- byte[] bytes = bos.toByteArray();
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-
- DataInputStream dis = new DataInputStream(bis);
-
- String s2 = SafeUTF.safeReadUTF(dis);
-
- assertEquals(s, s2);
- }
-
- public void testSafeWriteReadUTFTest2() throws Exception
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- DataOutputStream dos = new DataOutputStream(bos);
-
- String s = "abcdefghijklmnopqrstuvwxyz";
-
- SafeUTF.safeWriteUTF(dos, s);
-
- dos.close();
-
- byte[] bytes = bos.toByteArray();
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-
- DataInputStream dis = new DataInputStream(bis);
-
- String s2 = SafeUTF.safeReadUTF(dis);
-
- assertEquals(s, s2);
- }
-
- protected String genString(int len)
- {
- char[] chars = new char[len];
- for (int i = 0; i < len; i++)
- {
- chars[i] = (char)(65 + i % 26);
- }
- return new String(chars);
- }
-}
More information about the jboss-cvs-commits
mailing list