Package java.io

Examples of java.io.RandomAccessFile


    }
   
    public void run() {
      try {
        File tmp = new File(logFile);
        RandomAccessFile file;
        if (!tmp.exists()) {
            file = new RandomAccessFile(logFile,"rw");
            file.write(fileHeader.getBytes());
            file.write("<log>\n".getBytes());
          }
          else {
            file = new RandomAccessFile(logFile,"rw");
            file.getChannel().position(file.getChannel().size() "</log>".length());
          }
       
        while( ! stop ) {
          if (eventsToWrite.isEmpty()) {
            file.write("</log>".getBytes());
            file.close();
            return ;
          }
         
          String event = eventsToWrite.poll();
          try {
            file.write(event.getBytes());
          } catch (Throwable e) {
            e.printStackTrace();
            if (stop) {
              file.write("</log>".getBytes());
              file.close();
              return ;
            }
          }
        }
        file.write("</xml>".getBytes());
        file.close();
      }catch(Throwable t) {
        t.printStackTrace();
      }
    }
View Full Code Here


*/
public class SrcIndexDat {

  public static  Map<Int128, Index> loadFile(String fileName) throws Throwable {
    Map<Int128, Index> result = new Hashtable<Int128, Index>();
    FileChannel channel = new RandomAccessFile(fileName,"rw").getChannel();
   
    channel.position(4+4);
   
    ByteBuffer data;
   
View Full Code Here

 
  public void store() throws ServerMetException {
    try {
      fileChannel.close();
      file.delete();
      fileChannel = new RandomAccessFile(file,"rws").getChannel();
      fileChannel.position(0);
      ByteBuffer data;
   
      data = Misc.getByteBuffer(1);
      data.put(SERVERLIST_VERSION);
View Full Code Here

        // Grab the file name, there is a window when we
        // are writing the file, that some one else in
        // a different VM could get the same file name.
        try
        {
            RandomAccessFile file;
            file = new RandomAccessFile(exceptionFile, "rw");
            file.writeChar('t');
            file.close();
        }
        catch (Exception ex)
        {
            // ignore
        }
View Full Code Here

    try {
      File infoFile = new File(lockDir, INFO_FILE_NAME);
      File lockedFile = new File(lockDir, LOCK_FILE_NAME);

      RandomAccessFile raf = new RandomAccessFile(lockedFile, "rw");
      try {
        FileLock fileLock = raf.getChannel().lock();
        lock = createLock(raf, fileLock);
        sign(infoFile);
      }
      catch (IOException e) {
        if (lock != null) {
          // Also closes raf
          lock.release();
        }
        else {
          raf.close();
        }
        throw e;
      }
    }
    catch (IOException e) {
View Full Code Here

  private void removeInvalidLock(File lockDir) {
    try {
      boolean revokeLock = false;

      File lockedFile = new File(lockDir, LOCK_FILE_NAME);
      RandomAccessFile raf = new RandomAccessFile(lockedFile, "rw");
      try {
        FileLock fileLock = raf.getChannel().tryLock();

        if (fileLock != null) {
          logger.warn("Removing invalid lock {}", getLockedBy());
          fileLock.release();
          revokeLock = true;
        }
      }
      catch (OverlappingFileLockException exc) {
        // lock is still valid
      }
      finally {
        raf.close();
      }

      if (revokeLock) {
        revokeLock();
      }
View Full Code Here

     * @throws FileNotFoundException
     */
    private FileChannel getChannel() throws FileNotFoundException {

        if (channel == null) {
            channel = new RandomAccessFile(file, mode).getChannel();
        }

        return channel;
    }
View Full Code Here

  {
    super(maxRecords);
    this.recordSize = recordSize;

    this.cacheFile = File.createTempFile("txncache", ".dat", cacheDir);
    raf = new RandomAccessFile(cacheFile, "rw");
    fileChannel = raf.getChannel();
  }
View Full Code Here

        throw new IOException("Failed to create file: " + file);
      }
    }

    // Open a read/write channel to the file
    raf = new RandomAccessFile(file, "rw");
    fileChannel = raf.getChannel();

    if (fileChannel.size() == 0L) {
      // Empty file, insert bucket count, bucket size
      // and item count at the start of the file
View Full Code Here

        throw new IOException("Failed to create file " + file);
      }
    }

    // Open the file in read-write mode and make sure the file is empty
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    raf.setLength(0L);

    return raf;
  }
View Full Code Here

TOP

Related Classes of java.io.RandomAccessFile

Copyright © 2018 www.massapicom. 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.