1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.apksig.util; 18 19 import java.io.IOException; 20 import java.nio.ByteBuffer; 21 22 /** 23 * Consumer of input data which may be provided in one go or in chunks. 24 */ 25 public interface DataSink { 26 27 /** 28 * Consumes the provided chunk of data. 29 * 30 * <p>This data sink guarantees to not hold references to the provided buffer after this method 31 * terminates. 32 * 33 * @throws IndexOutOfBoundsException if {@code offset} or {@code length} are negative, or if 34 * {@code offset + length} is greater than {@code buf.length}. 35 */ consume(byte[] buf, int offset, int length)36 void consume(byte[] buf, int offset, int length) throws IOException; 37 38 /** 39 * Consumes all remaining data in the provided buffer and advances the buffer's position 40 * to the buffer's limit. 41 * 42 * <p>This data sink guarantees to not hold references to the provided buffer after this method 43 * terminates. 44 */ consume(ByteBuffer buf)45 void consume(ByteBuffer buf) throws IOException; 46 } 47