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 com.android.dx.util; 18 19 /** 20 * Interface for a sink for binary output. This is similar to 21 * <code>java.util.DataOutput</code>, but no <code>IOExceptions</code> 22 * are declared, and multibyte output is defined to be little-endian. 23 */ 24 public interface Output { 25 /** 26 * Gets the current cursor position. This is the same as the number of 27 * bytes written to this instance. 28 * 29 * @return >= 0; the cursor position 30 */ getCursor()31 public int getCursor(); 32 33 /** 34 * Asserts that the cursor is the given value. 35 * 36 * @param expectedCursor the expected cursor value 37 * @throws RuntimeException thrown if <code>getCursor() != 38 * expectedCursor</code> 39 */ assertCursor(int expectedCursor)40 public void assertCursor(int expectedCursor); 41 42 /** 43 * Writes a <code>byte</code> to this instance. 44 * 45 * @param value the value to write; all but the low 8 bits are ignored 46 */ writeByte(int value)47 public void writeByte(int value); 48 49 /** 50 * Writes a <code>short</code> to this instance. 51 * 52 * @param value the value to write; all but the low 16 bits are ignored 53 */ writeShort(int value)54 public void writeShort(int value); 55 56 /** 57 * Writes an <code>int</code> to this instance. 58 * 59 * @param value the value to write 60 */ writeInt(int value)61 public void writeInt(int value); 62 63 /** 64 * Writes a <code>long</code> to this instance. 65 * 66 * @param value the value to write 67 */ writeLong(long value)68 public void writeLong(long value); 69 70 /** 71 * Writes a DWARFv3-style unsigned LEB128 integer. For details, 72 * see the "Dalvik Executable Format" document or DWARF v3 section 73 * 7.6. 74 * 75 * @param value value to write, treated as an unsigned value 76 * @return 1..5; the number of bytes actually written 77 */ writeUnsignedLeb128(int value)78 public int writeUnsignedLeb128(int value); 79 80 /** 81 * Writes a DWARFv3-style unsigned LEB128 integer. For details, 82 * see the "Dalvik Executable Format" document or DWARF v3 section 83 * 7.6. 84 * 85 * @param value value to write 86 * @return 1..5; the number of bytes actually written 87 */ writeSignedLeb128(int value)88 public int writeSignedLeb128(int value); 89 90 /** 91 * Writes a {@link ByteArray} to this instance. 92 * 93 * @param bytes non-null; the array to write 94 */ write(ByteArray bytes)95 public void write(ByteArray bytes); 96 97 /** 98 * Writes a portion of a <code>byte[]</code> to this instance. 99 * 100 * @param bytes non-null; the array to write 101 * @param offset >= 0; offset into <code>bytes</code> for the first 102 * byte to write 103 * @param length >= 0; number of bytes to write 104 */ write(byte[] bytes, int offset, int length)105 public void write(byte[] bytes, int offset, int length); 106 107 /** 108 * Writes a <code>byte[]</code> to this instance. This is just 109 * a convenient shorthand for <code>write(bytes, 0, bytes.length)</code>. 110 * 111 * @param bytes non-null; the array to write 112 */ write(byte[] bytes)113 public void write(byte[] bytes); 114 115 /** 116 * Writes the given number of <code>0</code> bytes. 117 * 118 * @param count >= 0; the number of zeroes to write 119 */ writeZeroes(int count)120 public void writeZeroes(int count); 121 122 /** 123 * Adds extra bytes if necessary (with value <code>0</code>) to 124 * force alignment of the output cursor as given. 125 * 126 * @param alignment > 0; the alignment; must be a power of two 127 */ alignTo(int alignment)128 public void alignTo(int alignment); 129 } 130