Used the Strings.EMPTY_STRING instead of a new byte[0] in the code
git-svn-id: https://svn.apache.org/repos/asf/directory/shared/branches/shared-mvbt@1388934 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/asn1/api/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java b/asn1/api/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java
index 90aa86b..e91265c 100644
--- a/asn1/api/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java
+++ b/asn1/api/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java
@@ -37,8 +37,7 @@
/**
* The empty byte[]
*/
- public static final byte[] EMPTY_BYTES = new byte[]
- {};
+ public static final byte[] EMPTY_BYTES = new byte[0];
/**
@@ -89,7 +88,7 @@
{
if ( string == null )
{
- return new byte[0];
+ return EMPTY_BYTES;
}
try
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index fc5750c..a4b7c5b 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -355,7 +355,7 @@
{
super();
this.config = config;
-
+
if ( config.getBinaryAttributeDetector() == null )
{
config.setBinaryAttributeDetector( new DefaultConfigurableBinaryAttributeDetector() );
@@ -641,8 +641,9 @@
// Store the container into the session if we don't have one
LdapMessageContainer<MessageDecorator<? extends Message>> container =
- (LdapMessageContainer<MessageDecorator<? extends Message>>)ldapSession.getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR );
-
+ ( LdapMessageContainer<MessageDecorator<? extends Message>> ) ldapSession
+ .getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR );
+
if ( container == null )
{
ldapSession.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR,
@@ -1134,6 +1135,8 @@
{
return createBindRequest( name.getName(), credentials, null, ( Control[] ) null );
}
+
+
/**
* {@inheritDoc}
*/
@@ -3231,6 +3234,8 @@
{
loadSchema( new DefaultSchemaLoader( this ) );
}
+
+
/**
* loads schema using the specified schema loader
*
@@ -3253,7 +3258,7 @@
}
schemaManager = tmp;
-
+
// Change the container's BinaryDetector
ldapSession.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR,
new LdapMessageContainer<MessageDecorator<? extends Message>>( codec,
@@ -3674,7 +3679,7 @@
// deal with it immediately.
if ( sc.hasInitialResponse() )
{
- byte[] challengeResponse = sc.evaluateChallenge( new byte[0] );
+ byte[] challengeResponse = sc.evaluateChallenge( Strings.EMPTY_BYTES );
// Stores the challenge's response, and send it to the server
bindRequest.setCredentials( challengeResponse );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java b/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
index a15566f..14566c9 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
@@ -226,7 +226,7 @@
CodecControl<Control> control = ( org.apache.directory.shared.ldap.codec.api.CodecControl<Control> ) controls
.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
- assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+ assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
try
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/AddNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/AddNoDResponse.java
index f526eb0..2ac6449 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/AddNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/AddNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.AddResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final AddNoDResponse UNAVAILABLE = new AddNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/BindNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/BindNoDResponse.java
index 373ff90..eecf55b 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/BindNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/BindNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.BindResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final BindNoDResponse UNAVAILABLE = new BindNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/CompareNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/CompareNoDResponse.java
index e83d979..ed0ce27 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/CompareNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/CompareNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.CompareResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final CompareNoDResponse UNAVAILABLE = new CompareNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -82,13 +80,13 @@
// ExtendedResponse Interface Method Implementations
// ------------------------------------------------------------------------
/**
- * Gets the reponse OID specific encoded response values.
+ * Gets the response OID specific encoded response values.
*
* @return the response specific encoded response values.
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/DeleteNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/DeleteNoDResponse.java
index 5065b64..fde3c96 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/DeleteNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/DeleteNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.DeleteResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final DeleteNoDResponse UNAVAILABLE = new DeleteNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ExtendedNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ExtendedNoDResponse.java
index f976292..4c527b5 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ExtendedNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ExtendedNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -38,9 +39,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final ExtendedNoDResponse UNAVAILABLE = new ExtendedNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -91,7 +89,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyDnNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyDnNoDResponse.java
index 4a4bd00..ea4f77a 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyDnNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyDnNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.ModifyDnResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final ModifyDnNoDResponse UNAVAILABLE = new ModifyDnNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyNoDResponse.java
index 03047c4..61495c3 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/ModifyNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.ModifyResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final ModifyNoDResponse UNAVAILABLE = new ModifyNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/NoticeOfDisconnect.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/NoticeOfDisconnect.java
index 06e3c8b..ccae436 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/NoticeOfDisconnect.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/NoticeOfDisconnect.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.util.Strings;
/**
@@ -109,9 +110,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = "1.3.6.1.4.1.1466.20036";
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final NoticeOfDisconnect UNAVAILABLE = new NoticeOfDisconnect( ResultCodeEnum.UNAVAILABLE );
@@ -163,7 +161,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/SearchNoDResponse.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/SearchNoDResponse.java
index 11397f5..246b26e 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/SearchNoDResponse.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/extended/SearchNoDResponse.java
@@ -23,6 +23,7 @@
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.model.message.SearchResultDoneImpl;
+import org.apache.directory.shared.util.Strings;
/**
@@ -35,9 +36,6 @@
/** The OID of the NotiveOfDisconnect extended operation. */
public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
- /** The empty response */
- private static final byte[] EMPTY_RESPONSE = new byte[0];
-
/** The single instance with unavailable result code. */
public static final SearchNoDResponse UNAVAILABLE = new SearchNoDResponse( ResultCodeEnum.UNAVAILABLE );
@@ -88,7 +86,7 @@
*/
public byte[] getResponse()
{
- return EMPTY_RESPONSE;
+ return Strings.EMPTY_BYTES;
}
diff --git a/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/ByteArrayComparatorTest.java b/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/ByteArrayComparatorTest.java
index 3ca7578..2b0c561 100644
--- a/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/ByteArrayComparatorTest.java
+++ b/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/ByteArrayComparatorTest.java
@@ -22,12 +22,13 @@
import static org.junit.Assert.assertEquals;
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-import org.apache.directory.shared.ldap.model.schema.comparators.ByteArrayComparator;
+import org.apache.directory.shared.util.Strings;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
/**
* Testcase to test the ByteArrayComparator.
@@ -48,21 +49,21 @@
@Test
public void testB2Null()
{
- assertEquals( 1, new ByteArrayComparator( null ).compare( new byte[0], null ) );
+ assertEquals( 1, new ByteArrayComparator( null ).compare( Strings.EMPTY_BYTES, null ) );
}
@Test
public void testB1Null()
{
- assertEquals( -1, new ByteArrayComparator( null ).compare( null, new byte[0] ) );
+ assertEquals( -1, new ByteArrayComparator( null ).compare( null, Strings.EMPTY_BYTES ) );
}
@Test
public void testBothEmpty()
{
- assertEquals( 0, new ByteArrayComparator( null ).compare( new byte[0], new byte[0] ) );
+ assertEquals( 0, new ByteArrayComparator( null ).compare( Strings.EMPTY_BYTES, Strings.EMPTY_BYTES ) );
}
diff --git a/util/src/main/java/org/apache/directory/shared/util/Strings.java b/util/src/main/java/org/apache/directory/shared/util/Strings.java
index fd30754..7425017 100644
--- a/util/src/main/java/org/apache/directory/shared/util/Strings.java
+++ b/util/src/main/java/org/apache/directory/shared/util/Strings.java
@@ -251,6 +251,9 @@
0, 0, 0, 0, 0, 0, 0, 0
};
+ /** A empty byte array */
+ public static final byte[] EMPTY_BYTES = new byte[0];
+
/**
* Private constructor
@@ -734,6 +737,47 @@
}
}
+ private static final byte[] UTF8 = new byte[]
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
+ 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
+ 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40,
+ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
+ 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
+ 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F };
+
+
+ private static String toStringArray( byte[] bytes ) throws Exception
+ {
+ if ( bytes == null )
+ {
+ return null;
+ }
+
+ if ( bytes.length == 0 )
+ {
+ return "";
+ }
+
+ char[] chars = new char[bytes.length];
+ int pos = 0;
+
+ try
+ {
+ for ( byte b : bytes )
+ {
+ chars[pos++] = ( char ) UTF8[b];
+ }
+ }
+ catch ( ArrayIndexOutOfBoundsException aioobe )
+ {
+ return new String( bytes, "UTF-8" );
+ }
+
+ return new String( chars );
+ }
+
/**
* Return an UTF-8 encoded String
@@ -748,15 +792,30 @@
return "";
}
+ char[] chars = new char[bytes.length];
+ int pos = 0;
+
try
{
- return new String( bytes, "UTF-8" );
+ for ( byte b : bytes )
+ {
+ chars[pos++] = ( char ) UTF8[b];
+ }
}
- catch ( UnsupportedEncodingException uee )
+ catch ( ArrayIndexOutOfBoundsException aioobe )
{
- // if this happens something is really strange
- throw new RuntimeException( uee );
+ try
+ {
+ return new String( bytes, "UTF-8" );
+ }
+ catch ( UnsupportedEncodingException uee )
+ {
+ // if this happens something is really strange
+ throw new RuntimeException( uee );
+ }
}
+
+ return new String( chars );
}
@@ -1551,7 +1610,7 @@
{
if ( string == null )
{
- return new byte[0];
+ return EMPTY_BYTES;
}
try