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.fs; 019 020import java.io.IOException; 021import java.nio.ByteBuffer; 022 023/** 024 * Implementers of this interface provide a read API that writes to a 025 * ByteBuffer, not a byte[]. 026 */ 027public 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() will be advanced by the number 033 * of bytes read and buf.limit() should be unchanged. 034 * <p/> 035 * In the case of an exception, the values of buf.position() and buf.limit() 036 * are undefined, and callers should be prepared to recover from this 037 * eventuality. 038 * <p/> 039 * Many implementations will throw {@link UnsupportedOperationException}, so 040 * callers that are not confident in support for this method from the 041 * underlying filesystem should be prepared to handle that exception. 042 * <p/> 043 * Implementations should treat 0-length requests as legitimate, and must not 044 * signal an error upon their receipt. 045 * 046 * @param buf 047 * the ByteBuffer to receive the results of the read operation. 048 * @return the number of bytes read, possibly zero, or -1 if 049 * reach end-of-stream 050 * @throws IOException 051 * if there is some error performing the read 052 */ 053 public int read(ByteBuffer buf) throws IOException; 054}