/* * Copyright (C) 2016 The Android Open Source Project * * Licensed 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.android.apksig.util; import java.io.IOException; import java.nio.ByteBuffer; /** * Abstract representation of a source of data. * *
This abstraction serves three purposes: *
There are following ways to obtain a chunk of data from the data source: *
The returned buffer's position is {@code 0}, and the buffer's limit and capacity is * {@code size}. * * @param offset index (in bytes) at which the chunk starts inside data source * @param size size (in bytes) of the chunk * * @throws IndexOutOfBoundsException if {@code offset} or {@code size} is negative, or if * {@code offset + size} is greater than {@link #size()}. */ ByteBuffer getByteBuffer(long offset, int size) throws IOException; /** * Copies the specified chunk from this data source into the provided destination buffer, * advancing the destination buffer's position by {@code size}. * * @param offset index (in bytes) at which the chunk starts inside data source * @param size size (in bytes) of the chunk * * @throws IndexOutOfBoundsException if {@code offset} or {@code size} is negative, or if * {@code offset + size} is greater than {@link #size()}. */ void copyTo(long offset, int size, ByteBuffer dest) throws IOException; /** * Returns a data source representing the specified region of data of this data source. Changes * to data represented by this data source will also be visible in the returned data source. * * @param offset index (in bytes) at which the region starts inside data source * @param size size (in bytes) of the region * * @throws IndexOutOfBoundsException if {@code offset} or {@code size} is negative, or if * {@code offset + size} is greater than {@link #size()}. */ DataSource slice(long offset, long size); }