Package java.nio.channels

Examples of java.nio.channels.FileChannel.map()


    try{
      FileChannel channel = fis.getChannel();
      try{
        long contentLength = content.length();
        //set the content to be a file channel.
        ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, contentLength);
        x.content = buffer;
        writer.append(x);
      }finally{
        channel.close();
      }
View Full Code Here


    FileInputStream fis = new FileInputStream(content);
    try{
      FileChannel channel = fis.getChannel();
      try{
        long contentLength = content.length();
        ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, contentLength);
        return getmd5(buffer);
      }finally{
        channel.close();
      }
    }finally{
View Full Code Here

      FileChannel rafc = raf.getChannel();
      for (int bufNr = 0; bufNr < nrBuffers; bufNr++) {
        int bufSize = (length > (bufferStart + maxBufSize))
          ? maxBufSize
          : (int) (length - bufferStart);
        this.buffers[bufNr] = rafc.map(MapMode.READ_ONLY,bufferStart,bufSize);
        this.bufSizes[bufNr] = bufSize;
        bufferStart += bufSize;
      }
      seek(0L);
    }
View Full Code Here

        boolean capped = false;
        int lineCount = 0;
        try {
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            FileChannel fc = raf.getChannel();
            MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
            CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Derby use a different charset on a foreign PC?
            Matcher lines = FULL_LINE_PATTERN.matcher(cb);
            Matcher text = textSearch == null ? null : textSearch.matcher("");
            max = Math.min(max, MAX_SEARCH_RESULTS);
            while(lines.find()) {
View Full Code Here

  }

  MappedByteBuffer loadMmapInternal() {
    try {
      FileChannel channel = dataStream.getChannel();
      MappedByteBuffer mmap = channel.map(MapMode.READ_ONLY, 0,
          Math.min(Integer.MAX_VALUE, channel.size()));
      if (LOG.isTraceEnabled()) {
        LOG.trace(this + ": created mmap of size " + channel.size());
      }
      return mmap;
View Full Code Here

    }

    public static void main(String[] args) throws SecurityException,
        IOException {
        FileChannel ch = new FileInputStream(args[0]).getChannel();
        ByteBuffer buf = ch.map(FileChannel.MapMode.READ_ONLY, 0, ch.size());
        JarBuffer jb = new JarBuffer(buf);

        for (Map.Entry<String, ByteBuffer> entry : jb.entries().entrySet()) {
            final ByteBuffer ebuf = entry.getValue();
            if (ebuf.limit() > 0) {
View Full Code Here

  private String readFile(String path) throws IOException {
    FileInputStream stream = new FileInputStream(new File(path));
    try {
      FileChannel fc = stream.getChannel();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
          fc.size());
      /* Instead of using default, pass in a decoder. */
      return Charset.forName("utf-8").decode(bb).toString();
    } finally {
      stream.close();
View Full Code Here

      long size) throws IOException {
    FileChannel channel = raf.getChannel();

    boolean threw = true;
    try {
      MappedByteBuffer mbb = channel.map(mode, 0, size);
      threw = false;
      return mbb;
    } finally {
      Closeables.close(channel, threw);
    }
View Full Code Here

        try {
            FileInputStream fis = new FileInputStream(filename);
            FileChannel fc = fis.getChannel();

            // Create a read-only CharBuffer on the file
            ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, 0,
                    (int) fc.size());

            cbuf = Charset.forName("utf-8").newDecoder().decode(bbuf);
        } catch (CharacterCodingException e) {
            // e.printStackTrace();
View Full Code Here

    String s = "";
    FileChannel fc = null;
    try {
      fc = new FileInputStream(filename).getChannel();

      final MappedByteBuffer byteBuffer = fc.map(
          FileChannel.MapMode.READ_ONLY, 0, fc.size());

      final int size = byteBuffer.capacity();
      if (size > 0) {
        // Retrieve all bytes in the buffer
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.