private void load() throws IOException { raf.seek(0); counts = raf.readLong(); }
/** * Reads a big-endian 64-bit double from the current position in this file. Blocks * until eight bytes have been read, the end of the file is reached or an * exception is thrown. * * @return the next double value from this file. * @throws EOFException * if the end of this file is detected. * @throws IOException * if this file is closed or another I/O error occurs. * @see #writeDouble(double) */ public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
/** * Constructor which reads a datagram from a random access file. * * @param raf * the random access file to read the datagram from. * * @throws IOException * if there is a problem initialising the datagram from the file */ public Datagram(RandomAccessFile raf) throws IOException { duration = raf.readLong(); if (duration < 0) { throw new IOException("Can't create a datagram with a negative duration [" + duration + "]."); } int len = raf.readInt(); if (len < 0) { throw new IOException("Can't create a datagram with a negative data size [" + len + "]."); } data = new byte[len]; raf.readFully(data); }
/** * Constructor which reads a datagram from a random access file. * * @param raf * the random access file to read the datagram from. * * @throws IOException * if there is a problem initialising the datagram from the file */ public Datagram(RandomAccessFile raf) throws IOException { duration = raf.readLong(); if (duration < 0) { throw new IOException("Can't create a datagram with a negative duration [" + duration + "]."); } int len = raf.readInt(); if (len < 0) { throw new IOException("Can't create a datagram with a negative data size [" + len + "]."); } data = new byte[len]; raf.readFully(data); }
protected long readHeader(RandomAccessFile raFile) throws IOException { raFile.seek(0); if (raFile.length() == 0) return -1; String versionHint = raFile.readUTF(); if (!"GH".equals(versionHint)) throw new IllegalArgumentException("Not a GraphHopper file! Expected 'GH' as file marker but was " + versionHint); long bytes = raFile.readLong(); setSegmentSize(raFile.readInt()); for (int i = 0; i < header.length; i++) { header[i] = raFile.readInt(); } return bytes; }
private synchronized int readLastChunkId() throws IOException { if (chunkMetaData.length() <= 0) return 0; int lastChunkId = chunkMetaData.readInt(); int removedPagesCount = chunkMetaData.readInt(); for (int i = 0; i < removedPagesCount; i++) removedPages.add(chunkMetaData.readLong()); int hashCodeToHostIdMapSize = chunkMetaData.readInt(); for (int i = 0; i < hashCodeToHostIdMapSize; i++) addHostIds(chunkMetaData.readUTF()); return lastChunkId; }
if (adjust((int)pstatus.readLong()) != pid) throw new IOException("pstatus PID mismatch"); // sanity check ppid = adjust((int)pstatus.readLong()); // AIX pids are stored as a 64 bit integer, if (adjust((int)psinfo.readLong()) != pid) throw new IOException("psinfo PID mismatch"); // sanity check if (adjust((int)psinfo.readLong()) != ppid) throw new IOException("psinfo PPID mismatch"); // sanity check pr_argp = adjustL(psinfo.readLong()); pr_envp = adjustL(psinfo.readLong()); } finally { psinfo.close();
@Override public long readLong(int offset) { checkRead(offset, LONG); try { seekToOffset(offset); return randomAccessFile.readLong(); } catch (IOException e) { throw new RuntimeException(e); } }
private synchronized TreeSet<Long> readRemovedPages() { try { TreeSet<Long> removedPages = new TreeSet<>(); if (chunkMetaData.length() > 8) { chunkMetaData.seek(4); int removedPagesCount = chunkMetaData.readInt(); for (int i = 0; i < removedPagesCount; i++) removedPages.add(chunkMetaData.readLong()); } return removedPages; } catch (IOException e) { throw panic(DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Failed to readRemovedPages", e)); } }
/** * Constructor which pops a datagram from a random access file. * * @param raf * the random access file to pop the datagram from. * @param noiseModel * the noise model * @throws IOException * IOException * @throws EOFException * EOFException */ public HnmDatagram(RandomAccessFile raf, int noiseModel) throws IOException, EOFException { super(raf.readLong()); // duration int len = raf.readInt(); if (len < 0) { throw new IOException("Can't create a datagram with a negative data size [" + len + "]."); } if (len < 4 * 3) { throw new IOException("Hnm with waveform noise datagram too short (len=" + len + "): cannot be shorter than the space needed for first three Hnm parameters (4*3)"); } // For speed concerns, read into a byte[] first: byte[] buf = new byte[len]; raf.readFully(buf); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); frame = new HntmSpeechFrame(dis, noiseModel); }
SequentialReader(File file) throws EOFException, IOException { super(file, null); RandomAccessFile fileHandle = getFileHandle(); int version = fileHandle.readInt(); if (version != getVersion()) { throw new IOException("Version is " + Integer.toHexString(version) + " expected " + Integer.toHexString(getVersion()) + " file: " + file.getCanonicalPath()); } setLogFileID(fileHandle.readInt()); setLastCheckpointPosition(fileHandle.readLong()); setLastCheckpointWriteOrderID(fileHandle.readLong()); }
/** * Constructor which pops a datagram from a random access file. * * @param raf * the random access file to pop the datagram from. * @param noiseModel * the noise model * @throws IOException * IOException * @throws EOFException * EOFException */ public HnmDatagram(RandomAccessFile raf, int noiseModel) throws IOException, EOFException { super(raf.readLong()); // duration int len = raf.readInt(); if (len < 0) { throw new IOException("Can't create a datagram with a negative data size [" + len + "]."); } if (len < 4 * 3) { throw new IOException("Hnm with waveform noise datagram too short (len=" + len + "): cannot be shorter than the space needed for first three Hnm parameters (4*3)"); } // For speed concerns, read into a byte[] first: byte[] buf = new byte[len]; raf.readFully(buf); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); frame = new HntmSpeechFrame(dis, noiseModel); }
@Override public long readLong() throws IOException { try { return getRaf().readLong(); } catch (IOException ioe) { handleException(); throw ioe; } }
public FNode(RandomAccessFile f) throws Throwable { offset = f.getFilePointer(); hash = f.readLong(); childOffset = f.readUnsignedShort(); numChildren = f.readUnsignedShort(); tagOffset = f.readUnsignedShort(); }
public FNode() throws IOException { offset = f.getFilePointer(); try { hash = f.readLong(); childOffset = f.readUnsignedShort(); numChildren = f.readUnsignedShort(); tagOffset = f.readUnsignedShort(); } catch (EOFException e) { numChildren = 0; tagOffset = 0; } }
LongBuffer revertBuffer() throws IOException { LongBuffer reverted = new LongBuffer(buffer.length); if (bufferSize < buffer.length) { for (int i=0;i<bufferSize;i++) { reverted.writeLong(buffer[bufferSize - 1 - i]); } } else { writeStream.flush(); RandomAccessFile raf = new RandomAccessFile(backingFile,"r"); long offset = raf.length(); while(offset > 0) { offset-=8; raf.seek(offset); reverted.writeLong(raf.readLong()); } } reverted.startReading(); return reverted; }
private FNode binarySearch(long start, int len, long hash) throws IOException { int b = 0; int e = len; while (b <= e) { int m = (b + e) / 2; f.seek(start + m * EftarFile.RECORD_LENGTH); long mhash = f.readLong(); if (hash > mhash) { b = m + 1; } else if (hash < mhash) { e = m - 1; } else { return new FNode(mhash, f.getFilePointer() - 8l, f.readUnsignedShort(), f.readUnsignedShort(), f.readUnsignedShort()); } } return null; }
private FNode sbinSearch(long start, int len, long hash, RandomAccessFile f) throws Throwable { int b = 0; int e = len; while (b <= e) { int m = (b + e) / 2; f.seek(start + m * RECORD_LENGTH); long mhash = f.readLong(); if (hash > mhash) { b = m + 1; } else if (hash < mhash) { e = m - 1; } else { return new FNode(mhash, f.getFilePointer() - 8l, f.readUnsignedShort(), f.readUnsignedShort(), f.readUnsignedShort()); } } return null; } }
protected MetaDataWriter(File file, int logFileID) throws IOException { super(file, logFileID); boolean error = true; try { RandomAccessFile writeFileHandle = getFileHandle(); int version = writeFileHandle.readInt(); if (version != getVersion()) { throw new IOException("The version of log file: " + file.getCanonicalPath() + " is different from expected " + " version: expected = " + getVersion() + ", found = " + version); } int fid = writeFileHandle.readInt(); if (fid != logFileID) { throw new IOException("The file id of log file: " + file.getCanonicalPath() + " is different from expected " + " id: expected = " + logFileID + ", found = " + fid); } setLastCheckpointOffset(writeFileHandle.readLong()); setLastCheckpointWriteOrderID(writeFileHandle.readLong()); LOGGER.info("File: " + file.getCanonicalPath() + " was last checkpointed " + "at position: " + getLastCheckpointOffset() + ", logWriteOrderID: " + getLastCheckpointWriteOrderID()); error = false; } finally { if (error) { close(); } } }