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 Tomcat 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("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("");
            long start = startDate == null ? 0 : startDate.getTime();
            long end = endDate == null ? 0 : endDate.getTime();
View Full Code Here

        mmapFile.deleteOnExit(); // in case we don't need files later.
      }

      try {
        FileChannel rwChannel = new RandomAccessFile(mmapFile, "rw").getChannel();
        buffer = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, size).order(byteOrder);
        rwChannel.close();
      } catch (FileNotFoundException e) {
        throw new RuntimeException("[should never happen!] can't find mmap file/dir " + mmapFile.getAbsolutePath(), e);
      } catch (IOException e) {
        throw new RuntimeException("unable to initialize mmap file " + mmapFile, e);
View Full Code Here

public class OpenMatlab5 {

    public static void main(String[] args) throws IOException {
        File file = new File("swiss_roll_data.matlab5");
        FileChannel channel = new FileInputStream(file).getChannel();
        ByteBuffer scan = channel.map(MapMode.READ_ONLY,0,channel.size());
        scan.order(ByteOrder.BIG_ENDIAN);
        /*
         * MATLAB Version 5 MAT-files begin with a 128-byte header made up of a
         * 124 byte text field and two, 16-bit flag fields. <P> The first 124
         * bytes of the header can contain text data in human-readable form.
View Full Code Here

        FileChannel channel = new FileInputStream(filename).getChannel();
        ByteBuffer header = ByteBuffer.allocate(8);
        channel.read(header);
        rows = header.getInt();
        columns = header.getInt();
        data = channel.map(MapMode.READ_ONLY, 8, channel.size() - 8).asDoubleBuffer();
    }
   
    public BufferedMatrix(int rows, int columns, DoubleBuffer data) {
        this.rows = rows;
        this.columns = columns;
View Full Code Here

            assert file.exists() : file;
            // memory mapped file
            FileInputStream input = new FileInputStream(file);
            FileChannel channel = input.getChannel();
            long fileLength = channel.size();
            MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength);
            // character buffer
            Charset charset = java.nio.charset.Charset.forName("UTF-8");
            CharsetDecoder decoder = charset.newDecoder();
            return decoder.decode(buffer);
        } catch (Exception ex) {
View Full Code Here

            assert file.exists() : file;
            // memory mapped file
            FileInputStream input = new FileInputStream(file);
            FileChannel channel = input.getChannel();
            long fileLength = channel.size();
            MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength);
            // character buffer
            Charset charset = java.nio.charset.Charset.forName("UTF-8");
            CharsetDecoder decoder = charset.newDecoder();
            return decoder.decode(buffer);
        } catch (Exception ex) {
View Full Code Here

            // for big matrices
            f.deleteOnExit();
            RandomAccessFile raf = new RandomAccessFile(f, "rw");
            FileChannel fc = raf.getChannel();
            DoubleBuffer contextBuffer =
                fc.map(MapMode.READ_WRITE, 0, size).asDoubleBuffer();
            fc.close();
            return new Duple<DoubleBuffer,File>(contextBuffer, f);
        } catch (IOException ioe) {
            throw new IOError(ioe);
        }
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.defaultCharset().decode(bb).toString();
    } finally {
      stream.close();
View Full Code Here

    public SvdlibcSparseBinaryFileRowIterator(File matrixFile)
            throws IOException {
        // Create the accessor for the data stream.
        RandomAccessFile raf = new RandomAccessFile(matrixFile, "r");
        FileChannel fc = raf.getChannel();
        data = fc.map(MapMode.READ_ONLY, 0, fc.size());
        fc.close();

        // Read the number of rows, columns, and non zero entries in the matrix.
        this.rows = data.getInt();
        this.cols = data.getInt();
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.