Refine search
if (firstBlockIndex == lastBlockIndex) stream.seek(blocks[firstBlockIndex].offset + firstBlockOffset); stream.read(buffer, 0, buffer.length); stream.seek(blocks[firstBlockIndex].offset + firstBlockOffset); stream.read(buffer, buffer_offset, blockSize - firstBlockOffset); buffer_offset += blockSize - firstBlockOffset; for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++) stream.seek(blocks[j].offset); stream.read(buffer, buffer_offset, blockSize); buffer_offset += blockSize; stream.seek(blocks[lastBlockIndex].offset); stream.read(buffer, buffer_offset, buffer.length - buffer_offset);
/** * Read a bit-packed integer value. * @param nBytes the total number of bytes used for all rows * @param bits the number of bits to read for the specified row * @param index the row index * @return the value for the given row and column * @throws IOException if the value could not be read */ private int readBits(int nBytes, int bits, int index) throws IOException { if (bits == 8) { return stream.read(); } else if (bits == 16) { return stream.readShort() & 0xffff; } else if (bits >= 32) { return stream.readInt(); } long fp = stream.getFilePointer(); stream.skipBytes((index * bits) / 8); int b = stream.read(); int mask = (int) Math.pow(2, bits) - 1; int bitIndex = index % (8 / bits); int value = b & (mask << (bitIndex * bits)); value >>= ((8 - (bitIndex * bits)) % 8); stream.seek(fp); return value; }
/** * Checks the TIFF header. * * @return true if little-endian, * false if big-endian, * or null if not a TIFF. */ public Boolean checkHeader() throws IOException { if (in.length() < 4) return null; // byte order must be II or MM in.seek(0); int endianOne = in.read(); int endianTwo = in.read(); boolean littleEndian = endianOne == TiffConstants.LITTLE && endianTwo == TiffConstants.LITTLE; // II boolean bigEndian = endianOne == TiffConstants.BIG && endianTwo == TiffConstants.BIG; // MM if (!littleEndian && !bigEndian) return null; // check magic number (42) in.order(littleEndian); short magic = in.readShort(); bigTiff = magic == TiffConstants.BIG_TIFF_MAGIC_NUMBER; if (magic != TiffConstants.MAGIC_NUMBER && magic != TiffConstants.BIG_TIFF_MAGIC_NUMBER) { return null; } return new Boolean(littleEndian); }
/** @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ @Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { if (!FormatTools.validStream(stream, HEADER_SIZE, false)) { return false; } stream.seek(ENDIANNESS_OFFSET); stream.order(stream.read() == 68); stream.seek(0); int x = stream.readInt(); if (x <= 0 || x >= stream.length()) { return false; } int y = stream.readInt(); if (y <= 0 || y >= stream.length()) { return false; } int z = stream.readInt(); if (z <= 0 || z >= stream.length()) { return false; } return true; }
/** * Read the tables for the current database file. * @throws IOException if the file could not be read * @throws MetakitException if the file is not valid for the Metakit format */ private void initialize() throws IOException, MetakitException { String magic = stream.readString(2); if (magic.equals("JL")) { littleEndian = true; } else if (!magic.equals("LJ")) { throw new MetakitException("Invalid magic string; got " + magic); } boolean valid = stream.read() == 26; if (!valid) { throw new MetakitException("'valid' flag was set to 'false'"); } int headerType = stream.read(); if (headerType != 0) { throw new MetakitException( "Header type " + headerType + " is not valid."); } long footerPointer = stream.readInt() - 16; stream.seek(footerPointer); readFooter(); }
compressionType = in.readUnsignedByte(); byte[] user_metadata = new byte[KLB_METADATA_SIZE]; in.read(user_metadata); in.seek(offsetFilePointer + (requiredBlockNum * blocksPerPlane * 8)); for (int i=0; i < blocksPerPlane; i++) { blockOffsets[i+1] = readUInt64(); in.seek(offsetFilePointer + (requiredBlockNum * blocksPerPlane * 8) - 8); blockOffsets[0] = readUInt64(); } else { blockOffsets[0] = 0; in.seek(filePoointer);
/** * Detect the correct endianness and set the stream accordingly. * New-style headers have a value that can be checked, but older * headers do not (and are assumed to be little endian). * See the definition of offsets 196-216 in: * https://bio3d.colorado.edu/imod/doc/mrc_format.txt */ private void setLittleEndian(RandomAccessInputStream s) throws IOException { s.seek(ENDIANNESS_OFFSET); int check = s.read(); boolean little = check == 68; boolean big = check == 17; if (little == big) { little = true; } s.order(little); }
@Override public void fillInData() throws IOException { super.fillInData(); RandomAccessInputStream s = getStream(); try { s.order(true); s.seek(startingPosition + HEADER_SIZE); int xmlSize = s.readInt(); int attachmentSize = s.readInt(); s.skipBytes(248); xml = s.readString(xmlSize); attachment = new byte[attachmentSize]; s.read(attachment); } finally { if (stream == null) { s.close(); } } }
/** * Checks the TIFF header. * * @return true if little-endian, * false if big-endian, * or null if not a TIFF. */ public Boolean checkHeader() throws IOException { if (in.length() < 4) return null; // byte order must be II or MM in.seek(0); int endianOne = in.read(); int endianTwo = in.read(); boolean littleEndian = endianOne == TiffConstants.LITTLE && endianTwo == TiffConstants.LITTLE; // II boolean bigEndian = endianOne == TiffConstants.BIG && endianTwo == TiffConstants.BIG; // MM if (!littleEndian && !bigEndian) return null; // check magic number (42) in.order(littleEndian); short magic = in.readShort(); bigTiff = magic == TiffConstants.BIG_TIFF_MAGIC_NUMBER; if (magic != TiffConstants.MAGIC_NUMBER && magic != TiffConstants.BIG_TIFF_MAGIC_NUMBER) { return null; } return new Boolean(littleEndian); }
/** * Get the data from the block * * @return the block's data as a byte array * * @exception IOException if there is no data */ public byte [] getData() throws IOException { if (eof()) { throw new IOException("Cannot return empty data"); } byte[] b = new byte[length]; stream.seek(offset); stream.read(b); return b; }
private int getExtraSeries(String file) throws FormatException, IOException { if (in != null) in.close(); in = new RandomAccessInputStream(file, 16); boolean littleEndian = in.read() == TiffConstants.LITTLE; in.order(littleEndian); tiffParser = new TiffParser(in); IFD ifd = tiffParser.getFirstIFD(); RandomAccessInputStream ras = getCZTag(ifd); if (ras == null) return 1; ras.order(littleEndian); ras.seek(264); dimensionP = ras.readInt(); dimensionM = ras.readInt(); ras.close(); int nSeries = dimensionM * dimensionP; return nSeries <= 0 ? 1 : nSeries; }
@Override public void fillInData() throws IOException { super.fillInData(); RandomAccessInputStream s = getStream(); try { s.order(true); s.seek(startingPosition + HEADER_SIZE); int xmlSize = s.readInt(); int attachmentSize = s.readInt(); s.skipBytes(248); xml = s.readString(xmlSize); attachment = new byte[attachmentSize]; s.read(attachment); } finally { if (stream == null) { s.close(); } } }
private void findString(String marker) throws IOException { byte[] buf = new byte[8192]; int overlap = marker.length(); in.read(buf, 0, overlap); while (in.getFilePointer() < in.length()) { int length = in.read(buf, overlap, buf.length - overlap); for (int i=0; i<length; i++) { if (marker.equals( new String(buf, i, marker.length(), Constants.ENCODING))) { in.seek(in.getFilePointer() - (length + overlap) + i); return; } } System.arraycopy(buf, length, buf, 0, overlap); } }
private void findString(String marker) throws IOException { byte[] buf = new byte[8192]; int overlap = marker.length(); in.read(buf, 0, overlap); while (in.getFilePointer() < in.length()) { int length = in.read(buf, overlap, buf.length - overlap); for (int i=0; i<length; i++) { if (marker.equals( new String(buf, i, marker.length(), Constants.ENCODING))) { in.seek(in.getFilePointer() - (length + overlap) + i); return; } } System.arraycopy(buf, length, buf, 0, overlap); } }
private int getExtraSeries(String file) throws FormatException, IOException { if (in != null) in.close(); in = new RandomAccessInputStream(file, 16); boolean littleEndian = in.read() == TiffConstants.LITTLE; in.order(littleEndian); tiffParser = new TiffParser(in); IFD ifd = tiffParser.getFirstIFD(); RandomAccessInputStream ras = getCZTag(ifd); if (ras == null) return 1; ras.order(littleEndian); ras.seek(264); dimensionP = ras.readInt(); dimensionM = ras.readInt(); ras.close(); int nSeries = dimensionM * dimensionP; return nSeries <= 0 ? 1 : nSeries; }
private byte[] getFixedHeader() throws IOException { in.seek(offset); byte[] header = new byte[(int) (sos - offset)]; in.read(header); int index = (int) (imageDimensions - offset); DataTools.unpackBytes(tileDim, header, index, 2, false); DataTools.unpackBytes(tileDim, header, index + 2, 2, false); return header; }