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 */ 018 package org.apache.hadoop.fs; 019 020 import java.io.IOException; 021 import java.nio.ByteBuffer; 022 023 /** 024 * Implementers of this interface provide a read API that writes to a 025 * ByteBuffer, not a byte[]. 026 */ 027 public interface ByteBufferReadable { 028 /** 029 * Reads up to buf.remaining() bytes into buf. Callers should use 030 * buf.limit(..) to control the size of the desired read. 031 * <p/> 032 * After a successful call, buf.position() and buf.limit() should be 033 * unchanged, and therefore any data can be immediately read from buf. 034 * buf.mark() may be cleared or updated. 035 * <p/> 036 * In the case of an exception, the values of buf.position() and buf.limit() 037 * are undefined, and callers should be prepared to recover from this 038 * eventuality. 039 * <p/> 040 * Many implementations will throw {@link UnsupportedOperationException}, so 041 * callers that are not confident in support for this method from the 042 * underlying filesystem should be prepared to handle that exception. 043 * <p/> 044 * Implementations should treat 0-length requests as legitimate, and must not 045 * signal an error upon their receipt. 046 * 047 * @param buf 048 * the ByteBuffer to receive the results of the read operation. Up to 049 * buf.limit() - buf.position() bytes may be read. 050 * @return the number of bytes available to read from buf 051 * @throws IOException 052 * if there is some error performing the read 053 */ 054 public int read(ByteBuffer buf) throws IOException; 055 }