Esempio n. 1
0
  public void readFile(String path, Interfaces.Callback<ByteBuffer> cb) {
    Path file = Paths.get(path);
    AsynchronousFileChannel channel = openFileChannel(cb, file);

    if (channel == null) {
      return;
    }

    eventLoop.runInBackground(() -> Files.size(file), makeReader(channel, true, 0, cb));
  }
Esempio n. 2
0
  public void readFile(String path, String encoding, Interfaces.Callback<String> cb) {
    Path file = Paths.get(path);
    AsynchronousFileChannel channel = openFileChannel(cb, file);

    if (channel == null) {
      return;
    }
    eventLoop.runInBackground(
        () -> Files.size(file),
        makeReader(
            channel,
            true,
            0,
            (err, buffer) -> {
              Charset charset = Charset.forName(encoding);
              cb.invoke(null, new String(buffer.array(), 0, buffer.position(), charset));
            }));
  }