private String readLine(StringBuffer sb) throws IOException { boolean finished; do { int value = read(); finished = (value == -1 || value == 10); if (!finished) { sb.append((char) value); } } while (!finished); return sb.toString(); }
/** * This method guarantees to skip the next num bytes by read them from the underlying input. If the end of the file * is reached before num bytes are read an EOFException is thrown. This method doesn't use the skip() method of the * underlying input because skip() is not blocking and is not guaranteed to skip the given number of bytes for * different reasons. (CORE-107) * * @param numBytesToSkip number of bytes to skip. * @throws IOException if an I/O error occurs. * @throws EOFException if the end of file was reached before the given number of bytes could be skipped. */ private void skip(int numBytesToSkip) throws IOException { for (int bytesSkipped = 0; bytesSkipped < numBytesToSkip; bytesSkipped++) { if (read() == -1) throw new EOFException("Reached end of stream before " + numBytesToSkip + " bytes could be skipped"); } } }
private boolean checkSwf() throws IOException { // get rid of the last byte of the signature, the byte of the version and 4 bytes of the size byte[] a = new byte[6]; if (read(a) != a.length) { return false; } format = FORMAT_SWF; int bitSize = (int) readUBits(5); int maxX = readSBits(bitSize); int maxY = readSBits(bitSize); width = maxX / 20; // cause we're in twips height = maxY / 20; // cause we're in twips setPhysicalWidthDpi(72); setPhysicalHeightDpi(72); return (width > 0 && height > 0); }
private boolean checkSwf() throws IOException { // get rid of the last byte of the signature, the byte of the version and 4 bytes of the size byte[] a = new byte[6]; if (read(a) != a.length) { return false; } format = FORMAT_SWF; int bitSize = (int) readUBits(5); int maxX = readSBits(bitSize); int maxY = readSBits(bitSize); width = maxX / 20; // cause we're in twips height = maxY / 20; // cause we're in twips setPhysicalWidthDpi(72); setPhysicalHeightDpi(72); return (width > 0 && height > 0); }
private String readLine(StringBuffer sb, int finishValue) throws IOException { boolean finished; do { int value = read(); if (value == -1) { endOfStream = true; } finished = (value == -1 || value == finishValue); if (!finished) { sb.append((char) value); } } while (!finished); return sb.toString(); }
/** * This method guarantees to skip the next num bytes by read them from the underlying input. If the end of the file * is reached before num bytes are read an EOFException is thrown. This method doesn't use the skip() method of the * underlying input because skip() is not blocking and is not guaranteed to skip the given number of bytes for * different reasons. (CORE-107) * * @param numBytesToSkip number of bytes to skip. * @throws IOException if an I/O error occurs. * @throws EOFException if the end of file was reached before the given number of bytes could be skipped. */ private void skip(int numBytesToSkip) throws IOException { for (int bytesSkipped = 0; bytesSkipped < numBytesToSkip; bytesSkipped++) { if (read() == -1) throw new EOFException("Reached end of stream before " + numBytesToSkip + " bytes could be skipped"); } } }
private boolean checkPng() throws IOException { final byte[] PNG_MAGIC = { 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; byte[] a = new byte[27]; if (read(a) != 27) { return false; } if (!equals(a, 0, PNG_MAGIC, 0, 6)) { return false; } format = FORMAT_PNG; width = getIntBigEndian(a, 14); height = getIntBigEndian(a, 18); bitsPerPixel = a[22] & 0xff; int colorType = a[23] & 0xff; if (colorType == 2 || colorType == 6) { bitsPerPixel *= 3; } progressive = (a[26] & 0xff) != 0; return true; }
private boolean checkRas() throws IOException { byte[] a = new byte[14]; if (read(a) != a.length) { return false; } final byte[] RAS_MAGIC = {0x6a, (byte) 0x95}; if (!equals(a, 0, RAS_MAGIC, 0, 2)) { return false; } format = FORMAT_RAS; width = getIntBigEndian(a, 2); height = getIntBigEndian(a, 6); bitsPerPixel = getIntBigEndian(a, 10); return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 24); }
private boolean checkRas() throws IOException { byte[] a = new byte[14]; if (read(a) != a.length) { return false; } final byte[] RAS_MAGIC = { 0x6a, (byte) 0x95 }; if (!equals(a, 0, RAS_MAGIC, 0, 2)) { return false; } format = FORMAT_RAS; width = getIntBigEndian(a, 2); height = getIntBigEndian(a, 6); bitsPerPixel = getIntBigEndian(a, 10); return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 24); }
private boolean checkPng() throws IOException { final byte[] PNG_MAGIC = {0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}; byte[] a = new byte[31]; if (read(a) != 31) { return false; } if (!equals(a, 0, PNG_MAGIC, 0, 6)) { return false; } format = FORMAT_PNG; width = getIntBigEndian(a, 14); height = getIntBigEndian(a, 18); bitsPerPixel = a[22] & 0xff; int colorType = a[23] & 0xff; if (colorType == 2 || colorType == 6) { bitsPerPixel *= 3; } progressive = (a[26] & 0xff) != 0; // we are past IHDR chunk, validate the others until you find unknown chunk if (pngValidateMetadata) { return validatePngMetaData(); } else { return true; } }
private boolean checkPsd() throws IOException { byte[] a = new byte[24]; if (read(a) != a.length) { return false; } final byte[] PSD_MAGIC = {0x50, 0x53}; if (!equals(a, 0, PSD_MAGIC, 0, 2)) { return false; } format = FORMAT_PSD; width = getIntBigEndian(a, 16); height = getIntBigEndian(a, 12); int channels = getShortBigEndian(a, 10); int depth = getShortBigEndian(a, 20); bitsPerPixel = channels * depth; return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 64); }
private boolean checkPsd() throws IOException { byte[] a = new byte[24]; if (read(a) != a.length) { return false; } final byte[] PSD_MAGIC = { 0x50, 0x53 }; if (!equals(a, 0, PSD_MAGIC, 0, 2)) { return false; } format = FORMAT_PSD; width = getIntBigEndian(a, 16); height = getIntBigEndian(a, 12); int channels = getShortBigEndian(a, 10); int depth = getShortBigEndian(a, 20); bitsPerPixel = channels * depth; return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 64); }
private boolean checkJpeg() throws IOException { byte[] data = new byte[12]; while (true) { if (read(data, 0, 4) != 4) { return false; return false; // APPx header must be >= 14 bytes if (read(data, 0, 12) != 12) { return false; size -= 2; byte[] chars = new byte[size]; if (read(chars, 0, size) != size) { return false; addComment(comment); } else if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) { if (read(data, 0, 6) != 6) { return false;
private boolean checkBmp() throws IOException { byte[] a = new byte[44]; if (read(a) != a.length) { return false; } width = getIntLittleEndian(a, 16); height = getIntLittleEndian(a, 20); if (width < 1 || height < 1) { return false; } bitsPerPixel = getShortLittleEndian(a, 26); if (bitsPerPixel != 1 && bitsPerPixel != 4 && bitsPerPixel != 8 && bitsPerPixel != 16 && bitsPerPixel != 24 && bitsPerPixel != 32) { return false; } int x = (int) (getIntLittleEndian(a, 36) * 0.0254); if (x > 0) { setPhysicalWidthDpi(x); } int y = (int) (getIntLittleEndian(a, 40) * 0.0254); if (y > 0) { setPhysicalHeightDpi(y); } format = FORMAT_BMP; return true; }
private boolean checkBmp() throws IOException if (read(a) != a.length)
private boolean checkPcx() throws IOException { byte[] a = new byte[64]; if (read(a) != a.length) { return false;
private boolean checkPcx() throws IOException if (read(a) != a.length)