Package java.nio.channels

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


                       || (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


        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(System.getProperty("file.encoding")).decode(bb);
            Matcher target = null;
            Matcher any = null;
            Matcher lines = FULL_LINE_PATTERN.matcher(cb);
            Matcher text = textSearch == null ? null : textSearch.matcher("");
View Full Code Here

  public List<Long> fetchData(String path) throws IOException {
    List<Long> input = new ArrayList<Long>();
    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. */
      String[] lines = Charset.defaultCharset().decode(bb).toString()
          .split("\n");
      for(String line : lines) {
        long val = 0;
View Full Code Here

    public DirectNIOBuffer(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 MappedByteBuffer mapFile(File file) {
        try {
            FileChannel channel = new FileInputStream(file).getChannel();
            MappedByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, file.length());
            channel.close();
            return buffer;
        } catch(IOException e) {
            throw new VoldemortException(e);
        }
View Full Code Here


        FileChannel inChannel = inRandom.getChannel();

        //将输入文件的通道通过只读的权限 映射到内存中。
        MappedByteBuffer byteMapper = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) inFile.length());

        CharsetDecoder inDecoder = inCharset.newDecoder();
        CharsetEncoder outEncoder = outCharset.newEncoder();

        CharBuffer cb = inDecoder.decode(byteMapper);
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

    for (int bufNr = 0; bufNr < nrBuffers; bufNr++) {
      int bufSize = (int) ( (length > (bufferStart + chunkSize))
          ? chunkSize
              : (length - bufferStart)
          );
      buffers[bufNr] = rafc.map(MapMode.READ_ONLY, offset + bufferStart, bufSize);
      bufferStart += bufSize;
    }
   
    return buffers;
  }
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(logFile, "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

    static public String read(String path) throws MinException {
        try {
            FileInputStream stream = new FileInputStream(new java.io.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 java.nio.charset.Charset.defaultCharset().decode(bb).toString();
            } finally {
                stream.close();
            }
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.