private void openpfm() throws java.io.IOException { input.seek(0); vers = input.readShortLE(); h_len = input.readIntLE(); copyright = readString(60); type = input.readShortLE(); points = input.readShortLE(); verres = input.readShortLE(); horres = input.readShortLE(); ascent = input.readShortLE(); intleading = input.readShortLE(); extleading = input.readShortLE(); italic = (byte)input.read(); uline = (byte)input.read(); overs = (byte)input.read(); weight = input.readShortLE(); charset = (byte)input.read(); pixwidth = input.readShortLE(); pixheight = input.readShortLE(); kind = (byte)input.read(); avgwidth = input.readShortLE(); maxwidth = input.readShortLE(); firstchar = input.read(); lastchar = input.read(); defchar = (byte)input.read(); brkchar = (byte)input.read(); widthby = input.readShortLE(); device = input.readIntLE(); face = input.readIntLE(); bits = input.readIntLE();
public byte[] getFullFont() throws java.io.IOException { RandomAccessFileOrArray rf2 = null; try { rf2 = raf.createView(); byte[] b = new byte[(int) rf2.length()]; rf2.readFully(b); return b; } finally { try { if (rf2 != null) { rf2.close(); } } catch (Exception ignored) { } } }
protected int readNumGlyphs() throws java.io.IOException { int[] table_location = tables.get("maxp"); if (table_location == null) { return 65536; } else { raf.seek(table_location[0] + 4); return raf.readUnsignedShort(); } }
long newpos; pos = getPosition(); len = length(); newpos = pos + n; if (newpos > len) { newpos = len; seek(newpos);
public RandomAccessFileOrArray getPostscriptBinary() throws java.io.IOException { if (pfbData != null) { return new RandomAccessFileOrArray(sourceFactory.createSource(pfbData)); } else if (pfbPath != null && pfbPath.toLowerCase().endsWith(".pfb")) { return new RandomAccessFileOrArray(sourceFactory.createBestSource(pfbPath)); } else { pfbPath = afmPath.substring(0, afmPath.length() - 3) + "pfb"; return new RandomAccessFileOrArray(sourceFactory.createBestSource(pfbPath)); } }
/** * Load data from URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(url)); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(raf, stream); raf.close(); data = stream.toByteArray(); }
static byte[] readFontBytesFromPath(String path) throws java.io.IOException { RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createBestSource(path)); int bufLen = (int) raf.length(); if (bufLen < raf.length()) { throw new IOException(MessageFormatUtil.format("Source data from \"{0}\" is bigger than byte array can hold.", path)); } byte[] buf = new byte[bufLen]; raf.readFully(buf); return buf; } }
/** * If this font file is using the Compact Font File Format, then this method * will return the raw bytes needed for the font stream. If this method is * ever made public: make sure to add a test if (cff == true). * * @return a byte array */ public byte[] readCffFont() throws java.io.IOException { if (!isCff()) { return null; } RandomAccessFileOrArray rf2 = null; try { rf2 = raf.createView(); rf2.seek(cffOffset); byte[] cff = new byte[cffLength]; rf2.readFully(cff); return cff; } finally { try { if (rf2 != null) { rf2.close(); } } catch (Exception ignored) { } } }
try { raf = fontParser.getPostscriptBinary(); int fileLength = (int) raf.length(); fontStreamBytes = new byte[fileLength - 18]; fontStreamLengths = new int[3]; int bytePtr = 0; for (int k = 0; k < 3; ++k) { if (raf.read() != 0x80) { Logger logger = LoggerFactory.getLogger(Type1Font.class); logger.error(LogMessageConstant.START_MARKER_MISSING_IN_PFB_FILE); return null; if (raf.read() != PFB_TYPES[k]) { Logger logger = LoggerFactory.getLogger(Type1Font.class); logger.error("incorrect.segment.type.in.pfb.file"); return null; int size = raf.read(); size += raf.read() << 8; size += raf.read() << 16; size += raf.read() << 24; fontStreamLengths[k] = size; while (size != 0) { int got = raf.read(fontStreamBytes, bytePtr, size); if (got < 0) { Logger logger = LoggerFactory.getLogger(Type1Font.class); if (raf != null) { try {
/** * Reads the bytes to the buffer. This method will try to read as many bytes as the buffer can hold. * * @param b the destination buffer * @return the number of bytes actually read * @throws java.io.IOException in */ public int read(byte b[]) throws java.io.IOException { return read(b, 0, b.length); }
/** * Creates an independent view of this object (with it's own file pointer and push back queue). Closing the new object will not close this object. * Closing this object will have adverse effect on the view. * * @return the new view */ public RandomAccessFileOrArray createView() { ensureByteSourceIsThreadSafe(); return new RandomAccessFileOrArray(new IndependentRandomAccessSource(byteSource)); }
public long getStartxref() throws java.io.IOException { int arrLength = 1024; long fileLength = file.length(); long pos = fileLength - arrLength; if (pos < 1) pos = 1; while (pos > 0) { file.seek(pos); String str = readString(arrLength); int idx = str.lastIndexOf("startxref"); if (idx >= 0) return pos + idx; pos = pos - arrLength + 9; // 9 = "startxref".length() } throw new IOException(IOException.PdfStartxrefNotFound, this); }
public long length() throws java.io.IOException { return file.length(); }
/** * {@inheritDoc} */ public void readFully(byte b[]) throws java.io.IOException { readFully(b, 0, b.length); }
@Override public void close() throws java.io.IOException { if (raf != null) { raf.close(); } raf = null; }
void seek(int offset) { try { buf.seek(offset); } catch (java.io.IOException e) { throw new IOException(IOException.IoException, e); } }
public void read() throws java.io.IOException { if (this.read) { throw new IllegalStateException("already.attempted.a.read.on.this.jbig2.file"); } this.read = true; readFileHeader(); // Annex D if (this.sequential) { // D.1 do { Jbig2Segment tmp = readHeader(); readSegment(tmp); segments.put(tmp.segmentNumber, tmp); } while (this.ra.getPosition() < this.ra.length()); } else { // D.2 Jbig2Segment tmp; do { tmp = readHeader(); segments.put(tmp.segmentNumber, tmp); } while (tmp.type != END_OF_FILE); for (int integer : segments.keySet()) { readSegment(segments.get(integer)); } } }
@Override public void emit(byte[] buffer) { //System.err.println("range emit offset "+offset+" size="+length); try { buf.seek(offset); for (int i=myOffset; i<myOffset+length; i++) buffer[i] = buf.readByte(); } catch (java.io.IOException e) { throw new IOException(IOException.IoException, e); } //System.err.println("finished range emit"); } }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }