From: Clebert S. <csu...@jb...> - 2006-04-24 23:49:42
|
User: csuconic Date: 06/04/24 19:49:40 Modified: src/org/jboss/serial/util StringUtil.java Added: src/org/jboss/serial/util HashStringUtil.java Log: JBSER-60 - Improvements on sizing of streamed objects Revision Changes Path 1.9 +5 -5 jboss-serialization/src/org/jboss/serial/util/StringUtil.java (In the diff below, changes in quantity of whitespace are not shown.) Index: StringUtil.java =================================================================== RCS file: /cvsroot/jboss/jboss-serialization/src/org/jboss/serial/util/StringUtil.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -b -r1.8 -r1.9 --- StringUtil.java 20 Apr 2006 19:31:38 -0000 1.8 +++ StringUtil.java 24 Apr 2006 23:49:40 -0000 1.9 @@ -123,7 +123,7 @@ static ThreadLocal currenBuffer = new ThreadLocal(); - private static StringUtilBuffer getBuffer() + public static StringUtilBuffer getThreadLocalBuffer() { StringUtilBuffer retValue = (StringUtilBuffer)currenBuffer.get(); if (retValue==null) @@ -139,7 +139,7 @@ { if (optimizeStrings) { - StringUtilBuffer buffer = getBuffer(); + StringUtilBuffer buffer = getThreadLocalBuffer(); saveString (out,str,buffer); } else @@ -148,7 +148,7 @@ } } - public static String readString(DataInput input) throws IOException + /*public static String readString(DataInput input) throws IOException { if (optimizeStrings) { @@ -159,7 +159,7 @@ { return input.readUTF(); } - } + } */ private static void pullDataToBuffer(DataInput input, StringUtilBuffer.Position pos, byte[] byteBuffer, long currentPosition, long size) throws IOException { @@ -174,7 +174,7 @@ { if (!optimizeStrings) { - return readString(input); + return input.readUTF(); } long size = 0; 1.1 date: 2006/04/24 23:49:40; author: csuconic; state: Exp;jboss-serialization/src/org/jboss/serial/util/HashStringUtil.java Index: HashStringUtil.java =================================================================== /* * 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.serial.util; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.security.DigestOutputStream; import java.security.MessageDigest; import org.apache.log4j.Logger; /** * * This code was extracted from MarshalledInvocation. It converts any string to a unique HashCode * @author Clebert Suconic * */ public class HashStringUtil { private static final Logger log = Logger.getLogger(HashStringUtil.class); private static final boolean isDebug = log.isDebugEnabled(); public static long hashName(String name) { try { long hash=0; ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512); MessageDigest messagedigest = MessageDigest.getInstance("SHA"); DataOutputStream dataoutputstream = new DataOutputStream(new DigestOutputStream(bytearrayoutputstream, messagedigest)); dataoutputstream.writeUTF(name); dataoutputstream.flush(); byte abyte0[] = messagedigest.digest(); for (int j = 0; j < Math.min(8, abyte0.length); j++) hash += (long) (abyte0[j] & 0xff) << j * 8; if (isDebug) { log.debug("hash on field " + name + " = " + hash); } return hash; } catch (Exception e) { RuntimeException rte = new RuntimeException(e); throw rte; } } } |