From 9fdb95ca9c3c8e3524845760b81a85c7a4c81a45 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 04 Dec 2009 11:49:33 +0000
Subject: [PATCH] Drop util package: move ByteString hierarchy into top level sdk package and other "internal" classes to com.sun.*. Move messages into their own package. Clean up imports.
---
sdk/src/com/sun/opends/sdk/util/StaticUtils.java | 93 +++++++++-------------------------------------
1 files changed, 19 insertions(+), 74 deletions(-)
diff --git a/sdk/src/org/opends/sdk/util/StaticUtils.java b/sdk/src/com/sun/opends/sdk/util/StaticUtils.java
similarity index 94%
rename from sdk/src/org/opends/sdk/util/StaticUtils.java
rename to sdk/src/com/sun/opends/sdk/util/StaticUtils.java
index 0eb960a..818389e 100644
--- a/sdk/src/org/opends/sdk/util/StaticUtils.java
+++ b/sdk/src/com/sun/opends/sdk/util/StaticUtils.java
@@ -25,11 +25,11 @@
* Copyright 2009 Sun Microsystems, Inc.
*/
-package org.opends.sdk.util;
+package com.sun.opends.sdk.util;
-import static com.sun.opends.sdk.util.Messages.*;
+import static com.sun.opends.sdk.messages.Messages.*;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
@@ -40,11 +40,11 @@
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import org.opends.sdk.ByteSequence;
+import org.opends.sdk.ByteString;
+import org.opends.sdk.ByteStringBuilder;
import org.opends.sdk.DecodeException;
-import com.sun.opends.sdk.util.Message;
-import com.sun.opends.sdk.util.MessageBuilder;
-import com.sun.opends.sdk.util.MessageDescriptor;
@@ -672,47 +672,21 @@
public static boolean compress(ByteSequence input,
ByteStringBuilder output)
{
- // Avoid extra copies if possible.
- byte[] inputBuffer;
- int inputOffset;
- final int inputLength = input.length();
+ byte[] inputBytes = input.toByteArray();
+ byte[] outputBytes = new byte[inputBytes.length];
- if (input instanceof ByteString)
- {
- final ByteString byteString = (ByteString) input;
- inputBuffer = byteString.buffer;
- inputOffset = byteString.offset;
- }
- else if (input instanceof ByteStringBuilder)
- {
- final ByteStringBuilder builder = (ByteStringBuilder) input;
- inputBuffer = builder.buffer;
- inputOffset = 0;
- }
- else
- {
- inputBuffer = new byte[inputLength];
- inputOffset = 0;
- input.copyTo(inputBuffer);
- }
-
- // Make sure the free space in the destination buffer is at least
- // as big as this.
- output.ensureAdditionalCapacity(inputLength);
-
- final int compressedSize = compress(inputBuffer, inputOffset,
- inputLength, output.buffer, output.length, output.buffer.length
- - output.length);
+ final int compressedSize = compress(inputBytes, 0,
+ inputBytes.length, outputBytes, 0, outputBytes.length);
if (compressedSize != -1)
{
if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE))
{
StaticUtils.DEBUG_LOG.fine(String.format("Compression %d/%d%n",
- compressedSize, inputLength));
+ compressedSize, inputBytes.length));
}
- output.length += compressedSize;
+ output.append(outputBytes, 0, compressedSize);
return true;
}
@@ -1752,53 +1726,24 @@
ByteStringBuilder output, int uncompressedSize)
throws DataFormatException
{
- // Avoid extra copies if possible.
- byte[] inputBuffer;
- int inputOffset;
- final int inputLength = input.length();
+ byte[] inputBytes = input.toByteArray();
+ byte[] outputBytes = new byte[uncompressedSize > 0 ? uncompressedSize : 0];
- if (input instanceof ByteString)
- {
- final ByteString byteString = (ByteString) input;
- inputBuffer = byteString.buffer;
- inputOffset = byteString.offset;
- }
- else if (input instanceof ByteStringBuilder)
- {
- final ByteStringBuilder builder = (ByteStringBuilder) input;
- inputBuffer = builder.buffer;
- inputOffset = 0;
- }
- else
- {
- inputBuffer = new byte[inputLength];
- inputOffset = 0;
- input.copyTo(inputBuffer);
- }
-
- // Resize destination buffer if a uncompressed size was provided.
- if (uncompressedSize > 0)
- {
- output.ensureAdditionalCapacity(uncompressedSize);
- }
-
- int decompressResult = uncompress(inputBuffer, inputOffset,
- inputLength, output.buffer, output.length, output.buffer.length
- - output.length);
+ int decompressResult = uncompress(inputBytes, 0,
+ inputBytes.length, outputBytes, 0, outputBytes.length);
if (decompressResult < 0)
{
// The destination buffer wasn't big enough. Resize and retry.
- output.ensureAdditionalCapacity(-decompressResult);
- decompressResult = uncompress(inputBuffer, inputOffset,
- inputLength, output.buffer, output.length,
- output.buffer.length - output.length);
+ outputBytes = new byte[-decompressResult];
+ decompressResult = uncompress(inputBytes, 0,
+ inputBytes.length, outputBytes, 0, outputBytes.length);
}
if (decompressResult >= 0)
{
// It was successful.
- output.length += decompressResult;
+ output.append(outputBytes, 0, decompressResult);
return true;
}
--
Gitblit v1.10.0