You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/02/03 08:19:50 UTC

svn commit: r151132 - in incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples: BufferedTuple.java ConstructedTuple.java DefinateLengthTuple.java IndefinateLengthTuple.java PrimitiveTuple.java StreamedTuple.java

Author: akarasulu
Date: Wed Feb  2 23:19:49 2005
New Revision: 151132

URL: http://svn.apache.org/viewcvs?view=rev&rev=151132
Log:
ooops forgot to add these from our docs

Added:
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/BufferedTuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/ConstructedTuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/DefinateLengthTuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/IndefinateLengthTuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/PrimitiveTuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/StreamedTuple.java

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/BufferedTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/BufferedTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/BufferedTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/BufferedTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,109 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A Tag, Length, Value Tuple whose Value is kept in memory.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BufferedTuple extends PrimitiveTuple
+{
+    /** an empty ByteBuffer array so we do not have to create one every time */
+    private static final ByteBuffer[] EMPTY_BBARRAY = new ByteBuffer[0];
+
+    /** contains ByteBuffers which contain parts of the value */
+    private final ArrayList value = new ArrayList();
+
+    /** pre-fab final unmodifiable wrapper around our modifiable list */
+    private final List unmodifiable = Collections.unmodifiableList( value );
+
+
+    /**
+     * Creates a new primitive Tag, Length, Value Tuple which buffers the value
+     * within memory.
+     *
+     * @param tag the pre-fabricated Tag for this Tuple
+     * @param startIndex the byte index into the PDU where this Tuple starts
+     */
+    public BufferedTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isBuffered()
+    {
+        return true;
+    }
+
+
+    /**
+     * Gets the value of this Tuple as a List of ByteBuffers.
+     *
+     * @return a list of ByteBuffers containing parts of the value
+     */
+    public final List getValue()
+    {
+        return unmodifiable;
+    }
+
+
+    /**
+     * Gets the value of this Tuple as an array ByteBuffers.
+     *
+     * @return an array of ByteBuffers containing parts of the value
+     */
+    public final ByteBuffer[] getValueBuffers()
+    {
+        return ( ByteBuffer[] ) value.toArray( EMPTY_BBARRAY );
+    }
+
+
+    /**
+     * Appends a ByteBuffer to the value.
+     *
+     * @param buffer the buffer to append to this Tuples value
+     */
+    public void append( ByteBuffer buffer )
+    {
+        value.add( buffer );
+    }
+
+
+    /**
+     * Appends an array of ByteBuffers to the value.
+     *
+     * @param buffers the buffer array to append to this Tuples value
+     */
+    public void append( ByteBuffer[] buffers )
+    {
+        for ( int ii = 0; ii < buffers.length; ii++ )
+        {
+            value.add( buffers[ii] );
+        }
+    }
+}
\ No newline at end of file

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/ConstructedTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/ConstructedTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/ConstructedTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/ConstructedTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,47 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class ConstructedTuple extends AbstractTuple
+{
+    public ConstructedTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isConstructed()
+    {
+        return true;
+    }
+
+    /**
+     * Gets whether or not the length of this constructed Tuple is of the
+     * definate form or of the indefinate length form.
+     *
+     * @return true if the length is definate, false if the length is of the
+     * indefinate form
+     */
+    public abstract boolean isLengthDefinate();
+}
\ No newline at end of file

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/DefinateLengthTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/DefinateLengthTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/DefinateLengthTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/DefinateLengthTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,67 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefinateLengthTuple extends ConstructedTuple
+{
+    /** the number of bytes used to compose the Tuple's length field */
+    protected int lengthFieldSz = 0;
+
+    /** the number of bytes used to compose the Tuple's value field */
+    protected int valueFieldSz = 0;
+
+
+    public DefinateLengthTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isLengthDefinate()
+    {
+        return true;
+    }
+
+
+    /**
+     * Gets the number of bytes in the length (L) field of this TLV Tuple.
+     *
+     * @return number of bytes for the length
+     */
+    public final int getLengthFieldSize()
+    {
+        return lengthFieldSz;
+    }
+
+
+    /**
+     * Gets the number of bytes in the value (V) field of this TLV Tuple.
+     *
+     * @return number of bytes for the value
+     */
+    public final int getValueFieldSize()
+    {
+        return valueFieldSz;
+    }
+}
\ No newline at end of file

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/IndefinateLengthTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/IndefinateLengthTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/IndefinateLengthTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/IndefinateLengthTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class IndefinateLengthTuple extends ConstructedTuple
+{
+    public IndefinateLengthTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isLengthDefinate()
+    {
+        return false;
+    }
+}

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/PrimitiveTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/PrimitiveTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/PrimitiveTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/PrimitiveTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,108 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+/**
+ * A primitive TLV Tuple.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class PrimitiveTuple extends AbstractTuple
+{
+    /** the number of bytes used to compose the Tuple's length field */
+    private int lengthFieldSz = 0;
+
+    /** the number of bytes used to compose the Tuple's value field */
+    private int valueFieldSz = 0;
+
+
+    /**
+     * Creates a primitive Tag, Length, Value Tuple.  Note that we do not ask
+     * for length and value sizes to be known in advance since this information
+     * may not arrive together.  At a minimum we do however need to know the
+     * start index and the tag.
+     *
+     * @param tag the pre-fabricated tag for the tuple
+     * @param startIndex the index of the first tuple byte within the PDU buffer
+     */
+    public PrimitiveTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isConstructed()
+    {
+        return false;
+    }
+
+
+    /**
+     * Gets whether or not this Tuple's value is buffered in memory or
+     * streamed to disk.
+     *
+     * @return true if the value is buffered in memory, false if it is streamed
+     * to disk
+     */
+    public abstract boolean isBuffered();
+
+
+    /**
+     * Gets the number of bytes in the length (L) field of this TLV Tuple.
+     *
+     * @return number of bytes for the length
+     */
+    public final int getLengthFieldSize()
+    {
+        return lengthFieldSz;
+    }
+
+
+    /**
+     * Sets the size of the length field for this Tuple.
+     *
+     * @param lengthFieldSz the size of the length field
+     */
+    public void setLengthFieldSize( int lengthFieldSz )
+    {
+        this.lengthFieldSz = lengthFieldSz;
+    }
+
+
+    /**
+     * Gets the number of bytes in the value (V) field of this TLV Tuple.
+     *
+     * @return number of bytes for the value
+     */
+    public final int getValueFieldSize()
+    {
+        return valueFieldSz;
+    }
+
+
+    /**
+     * Sets the size of the value field for this Tuple.
+     *
+     * @param valueFieldSz the size of the value field
+     */
+    public void setValueFieldSize( int valueFieldSz )
+    {
+        this.valueFieldSz = valueFieldSz;
+    }
+}

Added: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/StreamedTuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/StreamedTuple.java?view=auto&rev=151132
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/StreamedTuple.java (added)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/tuples/StreamedTuple.java Wed Feb  2 23:19:49 2005
@@ -0,0 +1,58 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.tuples;
+
+
+import java.io.InputStream;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class StreamedTuple extends PrimitiveTuple
+{
+
+
+    public StreamedTuple( Tag tag, int startIndex )
+    {
+        super( tag, startIndex );
+    }
+
+
+    public final boolean isBuffered()
+    {
+        return false;
+    }
+
+    // might experiment with a getURL to represent the source of
+    // the data stream - we need to discuss this on the list
+
+    /**
+     * Depending on the backing store used for accessing streamed data there
+     * may need to be multiple subclasses that implement this method.
+     *
+     * @return an InputStream that can be used to read this Tuple's streamed
+     * value data
+     */
+    public abstract InputStream getValueStream();
+
+    // another question is whether or not to offer a readable Channel instead
+    // of an InputStream?  This is another topic for discussion.
+}
\ No newline at end of file