Package java.nio.channels

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


     * @tests {@link java.nio.MappedByteBuffer#load()}
     */
    public void test_load() throws IOException {
        FileInputStream fileInputStream = new FileInputStream(tmpFile);
        FileChannel fileChannelRead = fileInputStream.getChannel();
        MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
                fileChannelRead.size());
       
        assertEquals(mmbRead, mmbRead.load());

        RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
View Full Code Here


       
        assertEquals(mmbRead, mmbRead.load());

        RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
        FileChannel fileChannelReadWrite = randomFile.getChannel();
        MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
                FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());

        assertEquals(mmbReadWrite, mmbReadWrite.load());
       
        fileChannelRead.close();
View Full Code Here

  private byte[] mapFileIn(File infile) throws IOException{
    FileInputStream fis = new FileInputStream(infile);
    try{
      FileChannel fc = fis.getChannel(); // Get the file's size and then map it into memory
      int sz = (int)fc.size();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
      byte[] data2 = new byte[bb.remaining()];
      bb.get(data2);
      return data2;
    }
    finally{//Ensures resources are closed regardless of whether the action suceeded
View Full Code Here

            size = (int) (ch.size() - ch.position());
        }

        LOG.debug("getByteBuffer: pos=" + ch.position() + " size=" + size + " channel.size=" +
                ch.size());
        ByteBuffer bb = ch.map(MapMode.READ_ONLY, ch.position(), size);
        bb.order(BYTE_ORDER);

        if (LOG.isDebugEnabled()) {
            LOG.debug("bb=" + bb.toString() + " content=" + bb.duplicate().asCharBuffer());
        }
View Full Code Here

               {
                  chf = SpoolFile.createTempFile("jcrvdedit", null, tempDirectory);
                  chch = new RandomAccessFile(chf, "rw").getChannel();

                  // allocate the space for whole file
                  MappedByteBuffer bb = chch.map(FileChannel.MapMode.READ_WRITE, position + length, 0);
                  bb.force();
                  bb = null;

                  ReadableByteChannel bch = Channels.newChannel(new ByteArrayInputStream(this.data));
View Full Code Here

                  bch.close();

                  if (chch.size() < size)
                  {
                     // extend length
                     MappedByteBuffer bb = chch.map(FileChannel.MapMode.READ_WRITE, size, 0);
                     bb.force();
                  }
               }
               catch (final IOException e)
               {
View Full Code Here

    public NIOBuffer(File file) throws IOException
    {
        super(READONLY,NON_VOLATILE);
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
        setGetIndex(0);
        setPutIndex((int)file.length());
        _access=IMMUTABLE;
    }
View Full Code Here

    private int position;

    public MappedFileDataInput(FileInputStream stream, String filename, int position) throws IOException
    {
        FileChannel channel = stream.getChannel();
        buffer = channel.map(FileChannel.MapMode.READ_ONLY, position, channel.size());
        this.filename = filename;
        this.position = position;
    }

    public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position)
View Full Code Here

            if (src instanceof FileChannel) {
                FileChannel fileSrc = (FileChannel) src;
                long size = fileSrc.size();
                long filePosition = fileSrc.position();
                count = Math.min(count, size - filePosition);
                buffer = fileSrc.map(MapMode.READ_ONLY, filePosition, count);
                fileSrc.position(filePosition + count);
            } else {
                buffer = ByteBuffer.allocateDirect((int) count);
                src.read(buffer);
                buffer.flip();
View Full Code Here

                       || (start>0 && start<=logFileTime && end>0 && end>=logFileTime)) {

                        // It's in the range, so process the file
                        RandomAccessFile raf = new RandomAccessFile(logFiles[i], "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 Jetty use a different charset on a foreign PC?
                        Matcher lines = FULL_LINE_PATTERN.matcher(cb);
                        Matcher target = ACCESS_LOG_PATTERN.matcher("");
                        SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
                        int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);
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.