java.io.RandomAccessFile#readLong ( )源码实例Demo

下面列出了java.io.RandomAccessFile#readLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: TestRecordingFile.java
private static Path createBrokenMetadata(Path valid) throws Exception {
    try {
        Path broken = Utils.createTempFile("broken-metadata", ".jfr");
        Files.delete(broken);
        Files.copy(valid, broken);
        RandomAccessFile raf = new RandomAccessFile(broken.toFile(), "rw");
        raf.seek(METADATA_OFFSET);
        long metadataOffset = raf.readLong();
        raf.seek(metadataOffset);
        raf.writeLong(Long.MAX_VALUE);
        raf.writeLong(Long.MAX_VALUE);
        raf.close();
        return broken;
    } catch (IOException ioe) {
        throw new Exception("Could not produce a broken EventSet from file " + valid, ioe);
    }
}
 
源代码2 项目: openjdk-jdk8u   文件: TestRecordingFile.java
private static Path createBrokenMetadata(Path valid) throws Exception {
    try {
        Path broken = Utils.createTempFile("broken-metadata", ".jfr");
        Files.delete(broken);
        Files.copy(valid, broken);
        RandomAccessFile raf = new RandomAccessFile(broken.toFile(), "rw");
        raf.seek(METADATA_OFFSET);
        long metadataOffset = raf.readLong();
        raf.seek(metadataOffset);
        raf.writeLong(Long.MAX_VALUE);
        raf.writeLong(Long.MAX_VALUE);
        raf.close();
        return broken;
    } catch (IOException ioe) {
        throw new Exception("Could not produce a broken EventSet from file " + valid, ioe);
    }
}
 
源代码3 项目: tlaplus   文件: DiskFPSet.java
public long checkFPs() throws IOException {
	// It seems pointless to acquire the locks when checkFPs is only
	// executed after model checking has finished. Lock the disk
	// fingerprint sets though. Acquiring the locks is cheap.
	acquireTblWriteLock();
	flusher.flushTable();
	releaseTblWriteLock();

	RandomAccessFile braf = new BufferedRandomAccessFile(
			this.fpFilename, "r");
	long fileLen = braf.length();
	long dis = Long.MAX_VALUE;
	if (fileLen > 0) {
		long x = braf.readLong();
		while (braf.getFilePointer() < fileLen) {
			long y = braf.readLong();
			long dis1 = y - x;
			if (dis1 >= 0) {
				dis = Math.min(dis, dis1);
			}
			x = y;
		}
	}
	braf.close();
	return dis;
}
 
源代码4 项目: sgdtk   文件: OverlappedTrainingRunner.java
private void passN() throws IOException
{

    // Get FV from file
    randomAccessFile = new RandomAccessFile(getCacheFile(), "r");

    while (randomAccessFile.getFilePointer() < randomAccessFile.length())
    {
        int recordLength = (int) randomAccessFile.readLong();
        packBuffer = growIfNeeded(packBuffer, recordLength);
        randomAccessFile.read(packBuffer, 0, recordLength);
        FeatureVector fv = toFeatureVector();
        // add to ring buffer
        addWithProb(fv);

    }

    randomAccessFile.close();

    signalEndEpoch();

}
 
源代码5 项目: nyzoVerifier   文件: Block.java
public static Block fromFile(RandomAccessFile file) {

        Block block = null;

        try {
            ShortLong versionAndHeight = ShortLong.fromFile(file);
            int blockchainVersion = versionAndHeight.getShortValue();
            long blockHeight = versionAndHeight.getLongValue();
            byte[] previousBlockHash = Message.getByteArray(file, FieldByteSize.hash);
            long startTimestamp = file.readLong();
            long verificationTimestamp = file.readLong();
            int numberOfTransactions = file.readInt();
            List<Transaction> transactions = new ArrayList<>();
            for (int i = 0; i < numberOfTransactions; i++) {
                transactions.add(Transaction.fromFile(file, blockHeight, previousBlockHash, false));
            }

            byte[] balanceListHash = Message.getByteArray(file, FieldByteSize.hash);
            byte[] verifierIdentifier = Message.getByteArray(file, FieldByteSize.identifier);
            byte[] verifierSignature = Message.getByteArray(file, FieldByteSize.signature);

            // Transaction validation only needs to occur on blocks past the frozen edge.
            boolean validateTransactions = false;

            block = new Block(blockchainVersion, blockHeight, previousBlockHash, startTimestamp, verificationTimestamp,
                    transactions, balanceListHash, verifierIdentifier, verifierSignature, validateTransactions);
        } catch (Exception ignored) { }

        return block;
    }
 
源代码6 项目: nyzoVerifier   文件: ShortLong.java
public static ShortLong fromFile(RandomAccessFile file) {
    long combinedValue = 0;
    try {
        combinedValue = file.readLong();
    } catch (Exception ignored) { }
    int shortValue = (int) ((combinedValue >> 48) & 0xffff);
    long longValue = combinedValue & 0xffffffffffffL;
    return new ShortLong(shortValue, longValue);
}
 
源代码7 项目: btree4j   文件: Paged.java
protected void read(RandomAccessFile raf) throws IOException {
    this._fhSize = raf.readShort();
    this._pageSize = raf.readInt();
    this._totalPageCount = raf.readLong();
    this._firstFreePage = raf.readLong();
    this._lastFreePage = raf.readLong();
    this._pageHeaderSize = raf.readByte();
}
 
源代码8 项目: tlaplus   文件: OffHeapDiskFPSet.java
protected void writeIndex(long[] index, final RandomAccessFile raf, long length) throws IOException {
	for (int i = 0; i < index.length; i++) {
		long pos = Math.min(((long) i) * NumEntriesPerPage, length);
		raf.seek(pos * LongSize);
		final long value = raf.readLong();
		index[i] = value;
	}
}
 
源代码9 项目: tlaplus   文件: OffHeapDiskFPSet.java
private static boolean checkIndex(final long[] idx, final RandomAccessFile raf, final long length) throws IOException {
	for (long i = 0L; i < idx.length; i++) {
		final long pos = Math.min(i * NumEntriesPerPage, length);
		raf.seek(pos * LongSize);
		final long value = raf.readLong();
		final long index = idx[(int) i];
		if (value != index) {
			return false;
		}
	}
	return true;
}
 
/**
 * Constructs a new file header for an existing file
 *
 * @param randomAccessFile
 *            the existing file
 * @throws IOException
 *             if an I/O error occurs reading from the file
 */
public CheckpointCollectionFileHeader(RandomAccessFile randomAccessFile) throws IOException {
    fVersion = randomAccessFile.readInt();
    fSize = randomAccessFile.readInt();
    fNbEvents = randomAccessFile.readLong();
    ByteBuffer b = ByteBuffer.allocate(MAX_TIME_RANGE_SERIALIZE_SIZE);
    b.clear();
    fFileChannel.read(b);
    b.flip();
    fTimeRange = new TmfTimeRange(TmfTimestamp.create(b), TmfTimestamp.create(b));
}
 
源代码11 项目: hortonmachine   文件: DiskTreeReader.java
/**
 * Reads the {@link STRtree} object from the file.
 * 
 * @return the quadtree, holding envelops and geometry positions in the file.
 * @throws Exception
 */
public STRtree readIndex() throws Exception {

    File file = new File(path);
    raf = new RandomAccessFile(file, "r");

    raf.seek(6L);
    checkVersions();

    long position = INDEX_ADDRESS_POSITION;
    raf.seek(position);
    long indexAddress = raf.readLong();
    position = INDEX_ADDRESS_POSITION + INDEX_ADDRESS_SIZE;
    raf.seek(position);
    long indexSize = raf.readLong();

    raf.seek(indexAddress);
    byte[] indexBytes = new byte[(int) indexSize];
    int read = raf.read(indexBytes);
    if (read != indexSize) {
        throw new IOException();
    }

    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(indexBytes));
    indexObj = (STRtree) in.readObject();
    return indexObj;
}
 
源代码12 项目: jelectrum   文件: Lobstack.java
public Lobstack(File dir, String name, boolean compress, int key_step_size)
  throws IOException
{
  this.key_step_size  = key_step_size;
  this.dir = dir;
  this.stack_name = name;
  this.compress = compress;

  if (!dir.exists())
  {
    throw new java.io.IOException("Directory does not exist: " + dir);
  }
  if (!dir.isDirectory())
  {
    throw new java.io.IOException("Location is not a directory: " + dir);
  }

  data_files = new AutoCloseLRUCache<Long, FileChannel>(MAX_OPEN_FILES);

  RandomAccessFile root_file = new RandomAccessFile(new File(dir, name + ".root"), MODE);

  root_file_channel = root_file.getChannel();

  if (root_file.length()==0)
  {
    root_file.setLength(16);
    reset();
  }
  else
  {
    synchronized(ptr_lock)
    {
      root_file.seek(ROOT_ROOT_LOCATION);
      current_root = root_file.readLong();
      root_file.seek(ROOT_WRITE_LOCATION);
      current_write_location = root_file.readLong();
    }
  }
 
  showSize();

}
 
源代码13 项目: btree4j   文件: BTree.java
@Override
public synchronized void read(RandomAccessFile raf) throws IOException {
    super.read(raf);
    this._duplicateAllowed = raf.readBoolean();
    this._rootPage = raf.readLong();
}
 
源代码14 项目: birt   文件: ArchiveFile.java
protected void openArchiveForAppending( ) throws IOException
{
	// we need upgrade the document
	RandomAccessFile rf = new RandomAccessFile( archiveName, "rw" );
	if ( rf.length( ) == 0 )
	{
		// this is a empty file
		af = new ArchiveFileV3( archiveName, rf, "rw" );
	}
	else
	{
		try
		{
			long magicTag = rf.readLong( );
			if ( magicTag == ARCHIVE_V2_TAG )
			{
				af = new ArchiveFileV2( archiveName, rf, "rw+" );
			}
			else if ( magicTag == ARCHIVE_V3_TAG )
			{
				af = new ArchiveFileV3( archiveName, rf, "rw+" );
			}
			else if ( isZipFile( magicTag ) )
			{
				rf.close( );
				zipOnClose = true;
				tmpFileName = getTmpFileName( );
				unzip( archiveName, tmpFileName );
				ArchiveFileV3 fs = new ArchiveFileV3( tmpFileName, "rw+" );
				af = fs;
			}
			else
			{
				rf.close( );
				upgradeArchiveV1( );
				af = new ArchiveFileV3( archiveName, "rw+" );
			}
			upgradeSystemId( af );
		}
		catch ( IOException ex )
		{
			rf.close( );
			throw ex;
		}
	}
}
 
源代码15 项目: tlaplus   文件: DiskFPSet.java
public void recover(String fname) throws IOException {
	RandomAccessFile chkptRAF = new BufferedRandomAccessFile(
			this.getChkptName(fname, "chkpt"), "r");
	RandomAccessFile currRAF = new BufferedRandomAccessFile(
			this.fpFilename, "rw");

	this.fileCnt = chkptRAF.length() / LongSize;
	int indexLen = (int) ((this.fileCnt - 1) / NumEntriesPerPage) + 2;
	this.index = new long[indexLen];
	this.currIndex = 0;
	this.counter = 0;

	long fp = 0L;
	try {
		long predecessor = Long.MIN_VALUE;
		while (true) {
			fp = chkptRAF.readLong();
			this.writeFP(currRAF, fp);
			// check invariant
			Assert.check(predecessor < fp, EC.SYSTEM_INDEX_ERROR);
			predecessor = fp;
		}
	} catch (EOFException e) {
		Assert.check(this.currIndex == indexLen - 1, EC.SYSTEM_INDEX_ERROR);
		this.index[indexLen - 1] = fp;
	}

	chkptRAF.close();
	currRAF.close();

	// reopen a BufferedRAF for each thread
	for (int i = 0; i < this.braf.length; i++) {
		// Better way would be to provide method BRAF.open
		// close and reopen
		this.braf[i].close();
		this.braf[i] = new BufferedRandomAccessFile(this.fpFilename,
				"r");
	}
	for (int i = 0; i < this.brafPool.length; i++) {
		// Better way would be to provide method BRAF.open
		// close and reopen
		this.brafPool[i].close();
		this.brafPool[i] = new BufferedRandomAccessFile(
				this.fpFilename, "r");
	}
	this.poolIndex = 0;
}
 
源代码16 项目: tracecompass   文件: BTree.java
private BTreeHeader(RandomAccessFile randomAccessFile) throws IOException {
    super(randomAccessFile);

    fRoot = randomAccessFile.readLong();
    fSubVersion = randomAccessFile.readInt();
}
 
源代码17 项目: BPlusTree   文件: BPlusTree.java
/**
 * Reads an existing file and generates a B+ configuration based on the stored values
 *
 * @param r file to read from
 * @param generateConf generate configuration?
 * @return new configuration based on read values (if enabled) or null
 * @throws IOException is thrown when an I/O operation fails
 * @throws InvalidBTreeStateException is thrown when there are inconsistencies in the blocks.
 */
private BPlusConfiguration readFileHeader(RandomAccessFile r, boolean generateConf)
        throws IOException, InvalidBTreeStateException {
    r.seek(0L);

    // read the header number
    int headerNumber = r.readInt();

    if(headerNumber < 0)
        {throw new InvalidBTreeStateException("Negative header number found...");}

    // read the page size
    int pageSize = r.readInt();

    if(pageSize < 0)
        {throw new InvalidBTreeStateException("Cannot create a tree with negative page size");}

    // read the entry size
    int entrySize = r.readInt();

    if(entrySize <= 0)
        {throw new InvalidBTreeStateException("Entry size must be > 0");}

    // key size
    int keySize = r.readInt();

    if(keySize > 8 || keySize < 4)
        {throw new InvalidBTreeStateException("Key size but be either 4 or 8 bytes");}

    // read the number of pages (excluding the lookup)
    totalTreePages = r.readLong();

    if(totalTreePages < 0)
        {throw new InvalidBTreeStateException("Tree page number cannot be < 0");}


    // read the max page offset
    maxPageNumber = r.readLong();

    if(maxPageNumber < 0 || (totalTreePages > 0 && maxPageNumber == 0))
        {throw new InvalidBTreeStateException("Invalid max page offset");}

    // read the root index
    long rootIndex = r.readLong();

    if(rootIndex < 0)
        {throw new InvalidBTreeStateException("Root can't have index < 0");}

    // read the next lookup page pointer
    this.firstPoolNextPointer = r.readLong();

    // read the root.
    root = readNode(rootIndex);
    // finally if needed create a configuration file
    if(generateConf)
        {return(new BPlusConfiguration(pageSize, keySize, entrySize));}
    else
        {return(null);}
}
 
源代码18 项目: osmdroid   文件: GEMFFile.java
private void readHeader() throws IOException {
	final RandomAccessFile baseFile = mFiles.get(0);

	// Get file sizes
	for (final RandomAccessFile file : mFiles) {
		mFileSizes.add(file.length());
	}

	// Version
	final int version = baseFile.readInt();
	if (version != VERSION) {
		throw new IOException("Bad file version: " + version);
	}

	// Tile Size
	final int tile_size = baseFile.readInt();
	if (tile_size != TILE_SIZE) {
		throw new IOException("Bad tile size: " + tile_size);
	}

	// Read Source List
	final int sourceCount = baseFile.readInt();

	for (int i=0;i<sourceCount;i++) {
		final int sourceIndex = baseFile.readInt();
		final int sourceNameLength = baseFile.readInt();
		final byte[] nameData = new byte[sourceNameLength];
		baseFile.read(nameData, 0, sourceNameLength);

		final String sourceName = new String(nameData);
		mSources.put(new Integer(sourceIndex), sourceName);
	}

	// Read Ranges
	final int num_ranges = baseFile.readInt();
	for (int i=0;i<num_ranges;i++) {
		final GEMFRange rs = new GEMFRange();
		rs.zoom = baseFile.readInt();
		rs.xMin = baseFile.readInt();
		rs.xMax = baseFile.readInt();
		rs.yMin = baseFile.readInt();
		rs.yMax = baseFile.readInt();
		rs.sourceIndex = baseFile.readInt();
		rs.offset = baseFile.readLong();
		mRangeData.add(rs);
	}
}
 
源代码19 项目: sgdtk   文件: FeatureVector.java
/**
 * Read a dense vector in from a file.  Working memory will be allocated underneath.  Note that, for this reason,
 * OverlappedTrainingRunner does not use this memory, but instead uses a pre-allocated work buffer, which is resized
 * as necessary
 *
 * @param input A file
 * @return
 * @throws IOException
 */
public static FeatureVector deserializeDenseFrom(RandomAccessFile input) throws IOException
{
    int sz = (int)input.readLong();
    byte[] b = new byte[sz];
    input.read(b, 0, sz);
    FeatureVector fv = deserializeDense(b);
    return fv;
}
 
源代码20 项目: sgdtk   文件: FeatureVector.java
/**
 * Read a sparse vector in from a file.  Working memory will be allocated underneath.  Note that, for this reason,
 * OverlappedTrainingRunner does not use this memory, but instead uses a pre-allocated work buffer, which is resized
 * as necessary
 *
 * @param input A file
 * @return
 * @throws IOException
 */
public static FeatureVector deserializeSparseFrom(RandomAccessFile input) throws IOException
{
    int sz = (int)input.readLong();
    byte[] b = new byte[sz];
    input.read(b, 0, sz);
    FeatureVector fv = deserializeSparse(b);
    return fv;
}