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 public class Chunk { 36 37 /** 38 * Public members. Do not rename without updating the VM. 39 * 40 * @hide 41 */ 42 @SystemApi(client = MODULE_LIBRARIES) 43 public int type; // chunk type 44 /** 45 * @hide 46 */ 47 public byte[] data; // chunk data 48 /** 49 * @hide 50 */ 51 public int offset; // position within "dataf" 52 53 /** 54 * @hide 55 */ 56 public int length; 57 58 /** 59 * Blank constructor. Fill in your own fields. 60 * 61 * @hide 62 */ Chunk()63 public Chunk() {} 64 65 /** 66 * Constructor with all fields. 67 * 68 * @param type chunk type 69 * @param data chunk data 70 * @param offset offset in {@code data} where actual data starts from 71 * @param length length of the {@code data} 72 * 73 * @hide 74 */ 75 @SystemApi(client = MODULE_LIBRARIES) Chunk(int type, byte[] data, int offset, int length)76 public Chunk(int type, byte[] data, int offset, int length) { 77 this.type = type; 78 this.data = data; 79 this.offset = offset; 80 this.length = length; 81 } 82 83 /** 84 * Construct from a {@link ByteBuffer}. The chunk is assumed to start at 85 * offset 0 and continue to the current position. 86 * 87 * @param type chunk type 88 * @param buf {@link ByteBuffer} containing chunk data 89 * 90 * @hide 91 */ 92 @UnsupportedAppUsage 93 @SystemApi(client = MODULE_LIBRARIES) Chunk(int type, ByteBuffer buf)94 public Chunk(int type, ByteBuffer buf) { 95 this.type = type; 96 97 this.data = buf.array(); 98 this.offset = buf.arrayOffset(); 99 this.length = buf.position(); 100 } 101 } 102