1 /* 2 * Copyright (C) 2007 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 org.apache.harmony.dalvik.ddmc; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 import java.nio.ByteBuffer; 24 25 /** 26 * A chunk of DDM data. This is really just meant to hold a few pieces 27 * of data together. 28 * 29 * The "offset" and "length" fields are present so handlers can over-allocate 30 * or share byte buffers. 31 * 32 * @hide 33 */ 34 @SystemApi(client = MODULE_LIBRARIES) 35 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) 36 public class Chunk { 37 38 /** 39 * Public members. Do not rename without updating the VM. 40 * 41 * @hide 42 */ 43 @SystemApi(client = MODULE_LIBRARIES) 44 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) 45 public int type; // chunk type 46 /** 47 * @hide 48 */ 49 public byte[] data; // chunk data 50 /** 51 * @hide 52 */ 53 public int offset; // position within "dataf" 54 55 /** 56 * @hide 57 */ 58 public int length; 59 60 /** 61 * Blank constructor. Fill in your own fields. 62 * 63 * @hide 64 */ Chunk()65 public Chunk() {} 66 67 /** 68 * Constructor with all fields. 69 * 70 * @param type chunk type 71 * @param data chunk data 72 * @param offset offset in {@code data} where actual data starts from 73 * @param length length of the {@code data} 74 * 75 * @hide 76 */ 77 @SystemApi(client = MODULE_LIBRARIES) 78 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) Chunk(int type, byte[] data, int offset, int length)79 public Chunk(int type, byte[] data, int offset, int length) { 80 this.type = type; 81 this.data = data; 82 this.offset = offset; 83 this.length = length; 84 } 85 86 /** 87 * Construct from a {@link ByteBuffer}. The chunk is assumed to start at 88 * offset 0 and continue to the current position. 89 * 90 * @param type chunk type 91 * @param buf {@link ByteBuffer} containing chunk data 92 * 93 * @hide 94 */ 95 @UnsupportedAppUsage 96 @SystemApi(client = MODULE_LIBRARIES) 97 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) Chunk(int type, ByteBuffer buf)98 public Chunk(int type, ByteBuffer buf) { 99 this.type = type; 100 101 this.data = buf.array(); 102 this.offset = buf.arrayOffset(); 103 this.length = buf.position(); 104 } 105 } 106