Author: elecharny Date: Sun Oct 9 03:58:30 2005 New Revision: 307388 URL: http://svn.apache.org/viewcvs?rev=307388&view=rev Log: * deleted the length member, we use bytes.length instead * renamed the getLength method to getNbBytes Modified: directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java Modified: directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java?rev=307388&r1=307387&r2=307388&view=diff ============================================================================== --- directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java (original) +++ directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java Sun Oct 9 03:58:30 2005 @@ -50,9 +50,6 @@ /** The string is stored in a byte array */ private byte[] bytes; - /** Actual length of the string */ - private int length; - //~ Constructors ------------------------------------------------------------------------------- /** @@ -61,11 +58,8 @@ */ public OctetString( int length ) { - this.length = length; - if ( length > DEFAULT_LENGTH ) { - // TODO : implement the streaming isStreamed = true; bytes = new byte[length]; @@ -87,18 +81,15 @@ public OctetString( int length, boolean isStreamed ) { this.isStreamed = isStreamed; - this.length = length; if ( isStreamed ) { - // TODO : implement the streaming bytes = new byte[length]; } else { bytes = new byte[length]; - } } @@ -109,29 +100,27 @@ */ public OctetString( byte[] bytes ) { - length = bytes.length; - - if ( length > DEFAULT_LENGTH ) + if ( bytes.length > DEFAULT_LENGTH ) { isStreamed = true; // It will be a streamed OctetString. // TODO : implement the streaming - this.bytes = new byte[length]; + this.bytes = new byte[bytes.length]; // We have to copy the data, because the parameter // is not a copy. - System.arraycopy( bytes, 0, this.bytes, 0, length ); + System.arraycopy( bytes, 0, this.bytes, 0, bytes.length ); } else { isStreamed = false; - this.bytes = new byte[length]; + this.bytes = new byte[bytes.length]; // We have to copy the data, because the parameter // is not a copy. - System.arraycopy( bytes, 0, this.bytes, 0, length ); + System.arraycopy( bytes, 0, this.bytes, 0, bytes.length ); } } @@ -145,31 +134,23 @@ */ public void setData( byte[] bytes ) { - length = bytes.length; - - if ( length > DEFAULT_LENGTH ) + if ( bytes.length > DEFAULT_LENGTH ) { - if ( this.bytes.length < length ) + if ( this.bytes.length < bytes.length ) { - // The current size is too small. // We have to allocate more space // It will be a streamed OctetString. // TODO : implement the streaming - this.bytes = new byte[length]; + this.bytes = new byte[bytes.length]; } - // We have to copy the data, because the parameter - // is not a copy. - System.arraycopy( bytes, 0, this.bytes, 0, length ); + System.arraycopy( bytes, 0, this.bytes, 0, bytes.length ); } else { - - // We have to copy the data, because the parameter - // is not a copy. - System.arraycopy( bytes, 0, this.bytes, 0, length ); + System.arraycopy( bytes, 0, this.bytes, 0, bytes.length ); } } @@ -191,7 +172,7 @@ StringBuffer sb = new StringBuffer(); - for ( int i = 0; i < length; i++ ) + for ( int i = 0; i < bytes.length; i++ ) { if ( ( bytes[i] < 32 ) || ( bytes[i] > 127 ) ) { @@ -218,8 +199,8 @@ /** * @return Returns the length. */ - public int getLength() + public int getNbBytes() { - return length; + return bytes.length; } }