Package java.io

Examples of java.io.RandomAccessFile


     * @param pageSize should be greater than or equals to 64k.
     */
    public MemoryMappedFile(final File file, final int pageShift, final boolean readOnly, final boolean nativeByteOrder)
            throws FileNotFoundException {
        this._filepath = file.getAbsolutePath();
        RandomAccessFile raf = new RandomAccessFile(file, readOnly ? "r" : "rw");
        this._channel = raf.getChannel();
        this._readOnly = readOnly;
        this._setAsLittleEndian = nativeByteOrder
                && (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN);
        this._pageSize = 1 << pageShift;

View Full Code Here


        this._channel = null;
    }

    public synchronized void ensureOpen() {
        if(_channel == null) {
            final RandomAccessFile raf;
            try {
                raf = new RandomAccessFile(_filepath, _readOnly ? "r" : "rw");
            } catch (FileNotFoundException e) {
                throw new IllegalStateException("File not found: " + _filepath, e);
            }
            this._channel = raf.getChannel();
        }
    }
View Full Code Here

    this.file = file;
    this.order = order;
    this.protocolFilter = protocolFilter;
    this.rawBuilder = rawBuilder;
    this.channel = new RandomAccessFile(file, (mode.isContent()
        || mode.isAppend() ? "rw" : "r")).getChannel();
    this.mode = mode;
    this.headerReader = headerReader;

    final boolean readonly = !mode.isStructure();
View Full Code Here

     * Create a temp file
     */

    final File temp = File.createTempFile(this.file.getName(), null);

    final FileChannel tempChannel = new RandomAccessFile(temp, "rw")
        .getChannel();

    /*
     * Copy entire edits tree, including the root file, to temp file
     */
    for (final RegionSegment<PartialLoader> segment : this.edits) {
      final PartialLoader loader = new ConstrainedPartialLoader(segment
          .getData(), segment);

      loader.transferTo(tempChannel);
    }
    this.channel.close();
    tempChannel.close();

    System.gc();

    /*
     * We're done with the original file. All changes are now in the temp file
     * Try rename first, if it doesn't exist then do it by copy
     */
    if (file.delete() == false) {
      throw new IOException(
          "Unable to delete original file during flushByCopy()");
    }
    if (temp.renameTo(file) == false) {
      throw new IOException(
          "Unable to move temporary file during flushByCopy()");
    }

    final String accessMode = (mode.isContent() ? "rw" : "r");

    /*
     * Now we need to reopen the channel
     */
    this.channel = new RandomAccessFile(file, accessMode).getChannel();
  }
View Full Code Here

    if (dst.createNewFile() == false) {
      throw new FileNotFoundException("Unable to create dst file ["
          + dst.getName() + "]");
    }

    final FileChannel srcC = new RandomAccessFile(src, "r").getChannel();

    final FileChannel dstC = new RandomAccessFile(dst, "rw").getChannel();

    srcC.transferTo(0, srcC.size(), dstC);

    srcC.close();
    dstC.close();
View Full Code Here

    out.close();

  }

  public static long gzipUncompressedSize(File src) throws IOException {
    FileChannel in = new RandomAccessFile(src, "r").getChannel();

    ByteBuffer b = ByteBuffer.allocate(128);
    b.order(ByteOrder.LITTLE_ENDIAN);

    in.read(b, in.size() - b.remaining());
View Full Code Here

    return size;
  }

  public static long gzipUncompressedCRC32(File src) throws IOException {
    FileChannel in = new RandomAccessFile(src, "r").getChannel();

    ByteBuffer b = ByteBuffer.allocate(128);
    b.order(ByteOrder.LITTLE_ENDIAN);

    in.read(b, in.size() - b.remaining());
View Full Code Here

      /*
       * This is a plain uncompressed file, open up a FileChannel. It will be
       * much faster
       */
      return newInput(t, new RandomAccessFile(file, "rw").getChannel(), filter);
    }

    /*
     * Try with gunziped stream, second
     */
 
View Full Code Here

      /*
       * This is a plain uncompressed file, open up a FileChannel. It will be
       * much faster
       */
      return newInput(new RandomAccessFile(file, "rw").getChannel(), filter);
    }

    /*
     * Try with gunziped stream, second
     */
    b.reset(); // Rewind
    if (formatType(Channels.newChannel(new GZIPInputStream(b))) != null) {
      b.close();

      /*
       * Now reopen the same file, but this time without the buffered
       * inputstream in the middle. Try to make things as efficient as possible.
       * TODO: implement much faster channel based GZIP decompression algorithm
       */
      return newInput(Channels.newChannel(new GZIPInputStream(
          new FileInputStream(file))), filter);
    }

    b.close();
    return factoryForOther.getFactory().newInput(
        new RandomAccessFile(file, "r").getChannel(), filter);

  }
View Full Code Here

    }

    /*
     * Now try InputCapture which may also yield a known format
     */
    ReadableByteChannel channel = new RandomAccessFile(file, "r").getChannel();
    FormatType type = formatType(channel);
    channel.close();

    if (logger.isTraceEnabled()) {
      logger.trace(file.getName() + ", type=" + FormatType.Pcap);
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.