001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.io;
019
020import java.io.IOException;
021import java.nio.ByteBuffer;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * This interface marks a class to support writing ByteBuffers into it.
026 * @see ByteArrayOutputStream
027 * @see ByteBufferOutputStream
028 */
029@InterfaceAudience.Private
030public interface ByteBufferWriter {
031
032  /**
033   * Writes <code>len</code> bytes from the specified ByteBuffer starting at offset <code>off</code>
034   * @param b   the data.
035   * @param off the start offset in the data.
036   * @param len the number of bytes to write.
037   * @exception IOException if an I/O error occurs.
038   */
039  void write(ByteBuffer b, int off, int len) throws IOException;
040
041  /**
042   * Writes an <code>int</code> to the underlying output stream as four bytes, high byte first.
043   * @param i the <code>int</code> to write
044   * @throws IOException if an I/O error occurs.
045   */
046  // This is pure performance oriented API been added here. It has nothing to do with
047  // ByteBuffer and so not fully belong to here. This allows an int to be written at one go instead
048  // of 4 (4 bytes one by one).
049  // TODO remove it from here?
050  void writeInt(int i) throws IOException;
051}