1 /* 2 * Copyright (C) 2011 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.dex; 18 19 import com.android.dex.util.ByteArrayByteInput; 20 import com.android.dex.util.ByteInput; 21 22 /** 23 * An encoded value or array. 24 */ 25 public final class EncodedValue implements Comparable<EncodedValue> { 26 private final byte[] data; 27 EncodedValue(byte[] data)28 public EncodedValue(byte[] data) { 29 this.data = data; 30 } 31 asByteInput()32 public ByteInput asByteInput() { 33 return new ByteArrayByteInput(data); 34 } 35 getBytes()36 public byte[] getBytes() { 37 return data; 38 } 39 writeTo(Dex.Section out)40 public void writeTo(Dex.Section out) { 41 out.write(data); 42 } 43 compareTo(EncodedValue other)44 @Override public int compareTo(EncodedValue other) { 45 int size = Math.min(data.length, other.data.length); 46 for (int i = 0; i < size; i++) { 47 if (data[i] != other.data[i]) { 48 return (data[i] & 0xff) - (other.data[i] & 0xff); 49 } 50 } 51 return data.length - other.data.length; 52 } 53 toString()54 @Override public String toString() { 55 return Integer.toHexString(data[0] & 0xff) + "...(" + data.length + ")"; 56 } 57 } 58