// Path: hive-dwrf/src/main/java/com/facebook/hive/orc/compression/CompressionCodec.java
// public interface CompressionCodec {
//   /**
//    * Compress the in buffer to the out buffer.
//    * @param in the bytes to compress
//    * @param out the uncompressed bytes
//    * @param overflow put any additional bytes here
//    * @return true if the output is smaller than input
//    * @throws IOException
//    */
//   boolean compress(ByteBuffer in, ByteBuffer out, ByteBuffer overflow
//                   ) throws IOException;
// 
//   /**
//    * Decompress the in buffer to the out buffer.
//    * @param in the bytes to decompress
//    * @param out the decompressed bytes
//    * @throws IOException
//    */
//   void decompress(ByteBuffer in, ByteBuffer out) throws IOException;
// 
//   void reloadConfigurations(Configuration conf);
// }


import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import com.facebook.hive.orc.compression.CompressionCodec;
import org.apache.hadoop.hive.serde2.ReaderWriterProfiler;
//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 com.facebook.hive.orc;



class OutStream extends PositionedOutputStream {

  interface OutputReceiver {
    /**
     * Output the given buffer to the final destination
     * @param buffer the buffer to output
     * @throws IOException
     */
    void output(ByteBuffer buffer) throws IOException;
  }

  static final int HEADER_SIZE = 3;

  // If the OutStream is flushing the last compressed ByteBuffer, we don't need to reallocate
  // a new one, we can just share the same one over and over between streams because it gets
  // cleared right away.  It is a mapping from the size of the buffer to the buffer.
  private static final Map<Integer, ByteBuffer> COMPRESSED_FOR_REUSE =
    new HashMap<Integer, ByteBuffer>();

  private final String name;
  private final OutputReceiver receiver;

  /**
   * Stores the uncompressed bytes that have been serialized, but not
   * compressed yet. When this fills, we compress the entire buffer.
   */
  private ByteBuffer current = null;

  /**
   * Stores the compressed bytes until we have a full buffer and then outputs
   * them to the receiver. If no compression is being done, this (and overflow)
   * will always be null and the current buffer will be sent directly to the
   * receiver.
   */
  private ByteBuffer compressed = null;

  /**
   * Since the compressed buffer may start with contents from previous
   * compression blocks, we allocate an overflow buffer so that the
   * output of the codec can be split between the two buffers. After the
   * compressed buffer is sent to the receiver, the overflow buffer becomes
   * the new compressed buffer.
   */
  private ByteBuffer overflow = null;
  private final int bufferSize;
// Path: hive-dwrf/src/main/java/com/facebook/hive/orc/compression/CompressionCodec.java
// public interface CompressionCodec {
//   /**
//    * Compress the in buffer to the out buffer.
//    * @param in the bytes to compress
//    * @param out the uncompressed bytes
//    * @param overflow put any additional bytes here
//    * @return true if the output is smaller than input
//    * @throws IOException
//    */
//   boolean compress(ByteBuffer in, ByteBuffer out, ByteBuffer overflow
//                   ) throws IOException;
// 
//   /**
//    * Decompress the in buffer to the out buffer.
//    * @param in the bytes to decompress
//    * @param out the decompressed bytes
//    * @throws IOException
//    */
//   void decompress(ByteBuffer in, ByteBuffer out) throws IOException;
// 
//   void reloadConfigurations(Configuration conf);
// }


// Path: hive-dwrf/src/main/java/com/facebook/hive/orc/OutStream.java
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import com.facebook.hive.orc.compression.CompressionCodec;
import org.apache.hadoop.hive.serde2.ReaderWriterProfiler;

//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 com.facebook.hive.orc;



class OutStream extends PositionedOutputStream {

  interface OutputReceiver {
    /**
     * Output the given buffer to the final destination
     * @param buffer the buffer to output
     * @throws IOException
     */
    void output(ByteBuffer buffer) throws IOException;
  }

  static final int HEADER_SIZE = 3;

  // If the OutStream is flushing the last compressed ByteBuffer, we don't need to reallocate
  // a new one, we can just share the same one over and over between streams because it gets
  // cleared right away.  It is a mapping from the size of the buffer to the buffer.
  private static final Map<Integer, ByteBuffer> COMPRESSED_FOR_REUSE =
    new HashMap<Integer, ByteBuffer>();

  private final String name;
  private final OutputReceiver receiver;

  /**
   * Stores the uncompressed bytes that have been serialized, but not
   * compressed yet. When this fills, we compress the entire buffer.
   */
  private ByteBuffer current = null;

  /**
   * Stores the compressed bytes until we have a full buffer and then outputs
   * them to the receiver. If no compression is being done, this (and overflow)
   * will always be null and the current buffer will be sent directly to the
   * receiver.
   */
  private ByteBuffer compressed = null;

  /**
   * Since the compressed buffer may start with contents from previous
   * compression blocks, we allocate an overflow buffer so that the
   * output of the codec can be split between the two buffers. After the
   * compressed buffer is sent to the receiver, the overflow buffer becomes
   * the new compressed buffer.
   */
  private ByteBuffer overflow = null;
  private final int bufferSize;
  private final CompressionCodec codec;