1 21 22 package org.apache.derby.iapi.services.classfile; 23 24 import org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream; 25 import java.io.DataOutputStream ; 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 29 30 42 43 public final class ClassFormatOutput extends DataOutputStream { 44 45 public ClassFormatOutput() { 46 this(512); 47 } 48 49 public ClassFormatOutput(int size) { 50 this(new AccessibleByteArrayOutputStream(size)); 51 } 52 public ClassFormatOutput(java.io.OutputStream stream) { 53 super(stream); 54 } 55 public void putU1(int i) throws IOException { 56 if (i > 255) 59 ClassFormatOutput.limit("U1", 255, i); 60 write(i); 61 } 62 public void putU2(int i) throws IOException { 63 putU2("U2", i); 64 65 } 66 public void putU2(String limit, int i) throws IOException { 67 68 if (i > 65535) 71 ClassFormatOutput.limit(limit, 65535, i); 72 write(i >> 8); 73 write(i); 74 } 75 public void putU4(int i) throws IOException { 76 writeInt(i); 77 } 78 79 public void writeTo(OutputStream outTo) throws IOException { 80 ((AccessibleByteArrayOutputStream) out).writeTo(outTo); 81 } 82 83 87 public byte[] getData() { 88 return ((AccessibleByteArrayOutputStream) out).getInternalByteArray(); 89 } 90 91 98 static void limit(String name, int limit, int value) 99 throws IOException 100 { 101 throw new IOException (name + "(" + value + " > " + limit + ")"); 102 } 103 } 104 | Popular Tags |