Move the FrameOutputStream class to utils directory from io directory.
Also rewrite major parts of it to use the ByteArrayOutputStream extended
infrastructure to have the PrintStream write to byte array and copy
the byte array to the required ByteBuffer frame for result handling.
git-svn-id: https://hyracks.googlecode.com/svn/branches/fullstack_hyracks_result_distribution@2979 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameOutputStream.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameOutputStream.java
new file mode 100644
index 0000000..95833b1
--- /dev/null
+++ b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/io/FrameOutputStream.java
@@ -0,0 +1,53 @@
+/*
+ * 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.comm.io;
+
+import java.nio.ByteBuffer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.comm.io.FrameTupleAppender;
+
+public class FrameOutputStream extends ByteArrayAccessibleOutputStream {
+ private static final Logger LOGGER = Logger.getLogger(FrameOutputStream.class.getName());
+
+ private final FrameTupleAppender frameTupleAppender;
+
+ public FrameOutputStream(int frameSize) {
+ this.frameTupleAppender = new FrameTupleAppender(frameSize);
+ }
+
+ public void reset(ByteBuffer buffer, boolean clear) {
+ frameTupleAppender.reset(buffer, clear);
+ }
+
+ public int getTupleCount() {
+ int tupleCount = frameTupleAppender.getTupleCount();
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("appendTuple(): tuple count: " + tupleCount);
+ }
+ return tupleCount;
+ }
+
+ public boolean appendTuple() {
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("appendTuple(): tuple size: " + count);
+ }
+ boolean appended = frameTupleAppender.append(buf, 0, count);
+ count = 0;
+ return appended;
+ }
+}
diff --git a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/util/FrameOutputStream.java b/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/util/FrameOutputStream.java
deleted file mode 100644
index 73e5b74..0000000
--- a/hyracks/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/comm/util/FrameOutputStream.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.comm.util;
-
-import java.io.OutputStream;
-import java.nio.BufferOverflowException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import edu.uci.ics.hyracks.dataflow.common.comm.io.FrameTupleAppender;
-
-public class FrameOutputStream extends OutputStream {
- private static final Logger LOGGER = Logger.getLogger(FrameOutputStream.class.getName());
-
- private final FrameTupleAppender frameTupleAppender;
-
- public FrameOutputStream(FrameTupleAppender frameTupleAppender) {
- this.frameTupleAppender = frameTupleAppender;
- }
-
- @Override
- public void write(int intByte) {
- byte[] b = { (byte) intByte };
- if (LOGGER.isLoggable(Level.FINEST)) {
- LOGGER.finest("write(int): byte: " + b);
- }
- if (!frameTupleAppender.append(b, 0, 1)) {
- throw new BufferOverflowException();
- }
- }
-
- @Override
- public void write(byte[] bytes) {
- if (LOGGER.isLoggable(Level.FINEST)) {
- LOGGER.finest("write(bytes[]): bytes: " + bytes);
- }
- if (!frameTupleAppender.append(bytes, 0, bytes.length)) {
- throw new BufferOverflowException();
- }
- }
-
- @Override
- public void write(byte[] bytes, int offset, int length) {
- if (LOGGER.isLoggable(Level.FINEST)) {
- LOGGER.finest("write(bytes[]): bytes: " + bytes);
- }
- if (!frameTupleAppender.append(bytes, offset, length)) {
- throw new BufferOverflowException();
- }
- }
-}