1 31 package org.pdfbox.ttf; 32 33 import java.io.EOFException ; 34 import java.io.IOException ; 35 36 import java.util.Calendar ; 37 import java.util.GregorianCalendar ; 38 39 import org.pdfbox.cos.COSStream; 40 41 47 public abstract class TTFDataStream 48 { 49 50 56 public float read32Fixed() throws IOException 57 { 58 float retval = 0; 59 retval = readSignedShort(); 60 retval += (readUnsignedShort()/65536); 61 return retval; 62 } 63 64 70 public String readString( int length ) throws IOException 71 { 72 return readString( length, "ISO-8859-1" ); 73 } 74 75 82 public String readString( int length, String charset ) throws IOException 83 { 84 byte[] buffer = read( length ); 85 return new String (buffer, charset); 86 } 87 88 93 public abstract int read() throws IOException ; 94 95 100 public abstract long readLong() throws IOException ; 101 102 103 108 public int readSignedByte() throws IOException 109 { 110 return read() - 255; 111 } 112 113 118 public long readUnsignedInt() throws IOException 119 { 120 long byte1 = read(); 121 long byte2 = read(); 122 long byte3 = read(); 123 long byte4 = read(); 124 if( byte4 < 0 ) 125 { 126 throw new EOFException (); 127 } 128 return (byte1 << 24) + (byte2 << 16) + (byte3 << 8) + (byte4 << 0); 129 } 130 131 137 public abstract int readUnsignedShort() throws IOException ; 138 139 146 public int[] readUnsignedShortArray( int length ) throws IOException 147 { 148 int[] array = new int[ length ]; 149 for( int i=0; i<length; i++ ) 150 { 151 array[i] = readUnsignedShort(); 152 } 153 return array; 154 } 155 156 162 public abstract short readSignedShort() throws IOException ; 163 164 170 public Calendar readInternationalDate() throws IOException 171 { 172 long secondsSince1904 = readLong(); 173 GregorianCalendar cal = new GregorianCalendar ( 1904, 0, 1 ); 174 long millisFor1904 = cal.getTimeInMillis(); 175 millisFor1904 += (secondsSince1904*1000); 176 cal.setTimeInMillis( millisFor1904 ); 177 return cal; 178 } 179 180 185 public abstract void close() throws IOException ; 186 187 193 public abstract void seek(long pos) throws IOException ; 194 195 201 public byte[] read( int numberOfBytes ) throws IOException 202 { 203 byte[] data = new byte[ numberOfBytes ]; 204 int amountRead = 0; 205 int totalAmountRead = 0; 206 while( (amountRead = read( data, totalAmountRead, numberOfBytes-totalAmountRead ) ) != -1 && 207 totalAmountRead < numberOfBytes ) 208 { 209 totalAmountRead += amountRead; 210 } 212 return data; 213 } 214 215 226 public abstract int read(byte[] b, 227 int off, 228 int len) 229 throws IOException ; 230 231 236 public abstract long getCurrentPosition() throws IOException ; 237 238 250 public abstract COSStream getCOSStream(); 251 252 } | Popular Tags |