Added data accessors to help with binary data handling

git-svn-id: https://hyracks.googlecode.com/svn/trunk@79 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks/hyracks-api/src/main/java/edu/uci/ics/hyracks/api/comm/IFrameTupleAccessor.java b/hyracks/hyracks-api/src/main/java/edu/uci/ics/hyracks/api/comm/IFrameTupleAccessor.java
index 88b8768..0b4d3ff 100644
--- a/hyracks/hyracks-api/src/main/java/edu/uci/ics/hyracks/api/comm/IFrameTupleAccessor.java
+++ b/hyracks/hyracks-api/src/main/java/edu/uci/ics/hyracks/api/comm/IFrameTupleAccessor.java
@@ -1,3 +1,17 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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 edu.uci.ics.hyracks.api.comm;
 
 import java.nio.ByteBuffer;
@@ -9,6 +23,8 @@
 
     public int getFieldStartOffset(int tupleIndex, int fIdx);
 
+    public int getFieldLength(int tupleIndex, int fIdx);
+
     public int getTupleEndOffset(int tupleIndex);
 
     public int getTupleStartOffset(int tupleIndex);
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/ArrayTupleBuilder.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/ArrayTupleBuilder.java
index 09d8840..c39023b 100644
--- a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/ArrayTupleBuilder.java
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/ArrayTupleBuilder.java
@@ -21,8 +21,9 @@
 import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
 
-public class ArrayTupleBuilder {
+public class ArrayTupleBuilder implements IDataOutputProvider {
     private final ByteArrayAccessibleOutputStream baaos;
     private final DataOutputStream dos;
     private final int[] fEndOffsets;
@@ -80,6 +81,7 @@
         fEndOffsets[nextField++] = baaos.size();
     }
 
+    @Override
     public DataOutput getDataOutput() {
         return dos;
     }
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameTupleAccessor.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameTupleAccessor.java
index e282d82..7143cfc 100644
--- a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameTupleAccessor.java
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameTupleAccessor.java
@@ -80,6 +80,11 @@
     }
 
     @Override
+    public int getFieldLength(int tupleIndex, int fIdx) {
+        return getFieldEndOffset(tupleIndex, fIdx) - getFieldStartOffset(tupleIndex, fIdx);
+    }
+
+    @Override
     public int getFieldSlotsLength() {
         return recordDescriptor.getFields().length * 2;
     }
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/ArrayBackedValueStorage.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/ArrayBackedValueStorage.java
new file mode 100644
index 0000000..5dd1361
--- /dev/null
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/ArrayBackedValueStorage.java
@@ -0,0 +1,36 @@
+package edu.uci.ics.hyracks.dataflow.common.data.accessors;
+
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+
+import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+
+public class ArrayBackedValueStorage implements IValueReference, IDataOutputProvider {
+    private final ByteArrayAccessibleOutputStream baaos;
+    private final DataOutputStream dos;
+
+    public ArrayBackedValueStorage() {
+        baaos = new ByteArrayAccessibleOutputStream();
+        dos = new DataOutputStream(baaos);
+    }
+
+    @Override
+    public DataOutput getDataOutput() {
+        return dos;
+    }
+
+    @Override
+    public byte[] getBytes() {
+        return baaos.getByteArray();
+    }
+
+    @Override
+    public int getStartIndex() {
+        return 0;
+    }
+
+    @Override
+    public int getLength() {
+        return baaos.size();
+    }
+}
\ No newline at end of file
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/FrameTupleFieldValueReference.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/FrameTupleFieldValueReference.java
new file mode 100644
index 0000000..3cddbac
--- /dev/null
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/FrameTupleFieldValueReference.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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 edu.uci.ics.hyracks.dataflow.common.data.accessors;
+
+import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
+
+public class FrameTupleFieldValueReference implements IValueReference {
+    private IFrameTupleAccessor fta;
+    private int tupleIndex;
+    private int fieldIndex;
+
+    public FrameTupleFieldValueReference() {
+    }
+
+    public void reset(IFrameTupleAccessor fta, int tupleIndex, int fieldIndex) {
+        this.fta = fta;
+        this.tupleIndex = tupleIndex;
+        this.fieldIndex = fieldIndex;
+    }
+
+    @Override
+    public byte[] getBytes() {
+        return fta.getBuffer().array();
+    }
+
+    @Override
+    public int getStartIndex() {
+        return fta.getFieldStartOffset(tupleIndex, fieldIndex);
+    }
+
+    @Override
+    public int getLength() {
+        return fta.getFieldLength(tupleIndex, fieldIndex);
+    }
+}
\ No newline at end of file
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IDataOutputProvider.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IDataOutputProvider.java
new file mode 100644
index 0000000..fdfe2ec
--- /dev/null
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IDataOutputProvider.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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 edu.uci.ics.hyracks.dataflow.common.data.accessors;
+
+import java.io.DataOutput;
+
+public interface IDataOutputProvider {
+    public DataOutput getDataOutput();
+}
\ No newline at end of file
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IValueReference.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IValueReference.java
new file mode 100644
index 0000000..3c005de
--- /dev/null
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/data/accessors/IValueReference.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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 edu.uci.ics.hyracks.dataflow.common.data.accessors;
+
+public interface IValueReference {
+    public byte[] getBytes();
+
+    public int getStartIndex();
+
+    public int getLength();
+}
\ No newline at end of file