Package java.io

Examples of java.io.RandomAccessFile.seek()


      blockInFile.seek(blkOffset);
    }
    File metaFile = getMetaFile(blockFile, b);
    RandomAccessFile metaInFile = new RandomAccessFile(metaFile, "r");
    if (ckoff > 0) {
      metaInFile.seek(ckoff);
    }
    return new BlockInputStreams(new FileInputStream(blockInFile.getFD()),
                                new FileInputStream(metaInFile.getFD()));
  }
   
View Full Code Here


      Properties props = new Properties();
      setFields(props, this);
      RandomAccessFile file = new RandomAccessFile(to, "rws");
      FileOutputStream out = null;
      try {
        file.seek(0);
        out = new FileOutputStream(file.getFD());
        /*
         * If server is interrupted before this line,
         * the version file will remain unchanged.
         */
 
View Full Code Here

    try {
      //truncate blockFile
      blockRAF.setLength(newlen);
      //read last chunk
      blockRAF.seek(lastchunkoffset);
      blockRAF.readFully(b, 0, lastchunksize);
    } finally {
      blockRAF.close();
    }
View Full Code Here

    //update metaFile
    RandomAccessFile metaRAF = new RandomAccessFile(metaFile, "rw");
    try {
      metaRAF.setLength(newmetalen);
      metaRAF.seek(newmetalen - checksumsize);
      metaRAF.write(b, 0, checksumsize);
    } finally {
      metaRAF.close();
    }
  }
View Full Code Here

      if (blockFile.exists()) {
        RandomAccessFile raFile = new RandomAccessFile(blockFile, "rw");
        FileChannel channel = raFile.getChannel();
        String badString = "BADBAD";
        int rand = random.nextInt((int)channel.size()/2);
        raFile.seek(rand);
        raFile.write(badString.getBytes());
        raFile.close();
      }
    }
    // Read the file to trigger reportBadBlocks
View Full Code Here

        // Corrupt replica by writing random bytes into replica
        RandomAccessFile raFile = new RandomAccessFile(blockFile, "rw");
        FileChannel channel = raFile.getChannel();
        String badString = "BADBAD";
        int rand = random.nextInt((int)channel.size()/2);
        raFile.seek(rand);
        raFile.write(badString.getBytes());
        raFile.close();
      }
      corrupted = true;
    }
View Full Code Here

      try {
        System.out.println("Securely deleting "+file+" which is of length "+size+" bytes...");
        raf = new RandomAccessFile(file, "rw");
        long count;
        // Random data first.
        raf.seek(0);
        fill(new RandomAccessFileOutputStream(raf), size);
        raf.getFD().sync();
        raf.close();
        raf = null;
      } finally {
View Full Code Here

        try {
          oldBootID = Fields.bytesToLong(HexUtil.hexToBytes(s));
        } catch (NumberFormatException e) {
          oldBootID = -1;
        }
        raf.seek(0);
      }
      String s = HexUtil.bytesToHex(Fields.longToBytes(bootID));
      byte[] buf = s.getBytes("ISO-8859-1");
      if(buf.length != BOOT_FILE_LENGTH)
        System.err.println("Not 16 bytes for boot ID "+bootID+" - WTF??");
View Full Code Here

    }
    // check the layout version inside the image file
    File oldF = new File(oldImageDir, "fsimage");
    RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");
    try {
      oldFile.seek(0);
      int odlVersion = oldFile.readInt();
      if (odlVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION)
        return false;
    } finally {
      oldFile.close();
View Full Code Here

  private void writeConfigFile() {
    configLock.writeLock().lock();
    try {
      File tempConfig = new File(configFile.getPath() + ".tmp");
      RandomAccessFile raf = new RandomAccessFile(tempConfig, "rw");
      raf.seek(0);
      raf.write(cipherManager.getDiskSalt());

      raf.writeLong(storeSize);
      raf.writeLong(prevStoreSize);
      raf.writeLong(keyCount.get());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.