예제 #1
0
  public void add() {
    qprint.verbose("Add pressed. Create File");

    Display display = Display.getDefault();

    QFileManagerShell fm = new QFileManagerShell();
    while (!fm.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    QFileType file = fm.getFile();
    if (null == file) {
      qprint.error("file is null");
      return;
    }

    // create a new file and update tree
    File f = new File(file.getFilePath());
    try {
      qprint.verbose("create file " + f.getName());
      f.createNewFile();
      qtree.update();
    } catch (IOException e) {
      qprint.error("Imposible to create file");
    }
  }
예제 #2
0
 /**
  * Creates file blah: 0000 0001 0002 0003 . . . 3999
  *
  * <p>Blah extends beyond a single page of memory so that the ability to index into a file of
  * multiple pages is tested.
  */
 private static void initTestFile(File blah) throws Exception {
   try (BufferedWriter writer = Files.newBufferedWriter(blah.toPath(), ISO_8859_1)) {
     for (int i = 0; i < 4000; i++) {
       String number = new Integer(i).toString();
       for (int h = 0; h < 4 - number.length(); h++) writer.write("0");
       writer.write("" + i);
       writer.newLine();
     }
   }
 }
예제 #3
0
 public static void main(String[] args) throws Exception {
   blah = File.createTempFile("blah", null);
   blah.deleteOnExit();
   initTestFile(blah);
   try {
     out.println("Test file " + blah + " initialized");
     testZero();
     out.println("Zero size: OK");
     testRead();
     out.println("Read: OK");
     testWrite();
     out.println("Write: OK");
     testHighOffset();
     out.println("High offset: OK");
     testExceptions();
     out.println("Exceptions: OK");
   } finally {
     blah.delete();
   }
 }
예제 #4
0
  public static void main(String[] args) throws IOException {
    // open file but do not close it. Its existance will be checked by
    // the calling script.
    Paths.get(args[0]).newByteChannel(READ, WRITE, DELETE_ON_CLOSE);

    // check temporary file has been deleted after closing it
    Path file = File.createTempFile("blah", "tmp").toPath();
    file.newByteChannel(READ, WRITE, DELETE_ON_CLOSE).close();
    if (file.exists()) throw new RuntimeException("Temporary file was not deleted");

    Path dir = TestUtil.createTemporaryDirectory();
    try {
      // check that DELETE_ON_CLOSE fails when file is a sym link
      if (TestUtil.supportsLinks(dir)) {
        file = dir.resolve("foo").createFile();
        Path link = dir.resolve("link").createSymbolicLink(file);
        try {
          link.newByteChannel(READ, WRITE, DELETE_ON_CLOSE);
          throw new RuntimeException("IOException expected");
        } catch (IOException ignore) {
        }
      }

      // check that DELETE_ON_CLOSE works with files created via open
      // directories
      DirectoryStream stream = dir.newDirectoryStream();
      try {
        if (stream instanceof SecureDirectoryStream) {
          SecureDirectoryStream secure = (SecureDirectoryStream) stream;
          file = Paths.get("foo");

          Set<OpenOption> opts = new HashSet<OpenOption>();
          opts.add(WRITE);
          opts.add(DELETE_ON_CLOSE);
          secure.newByteChannel(file, opts).close();

          if (dir.resolve(file).exists()) throw new RuntimeException("File not deleted");
        }
      } finally {
        stream.close();
      }
    } finally {
      TestUtil.removeAll(dir);
    }
  }
예제 #5
0
  /** Test exceptions specified by map method */
  private static void testExceptions() throws Exception {
    // check exceptions when channel opened for read access
    try (FileChannel fc = FileChannel.open(blah.toPath(), READ)) {
      testExceptions(fc);

      checkException(fc, MapMode.READ_WRITE, 0L, fc.size(), NonWritableChannelException.class);

      checkException(
          fc,
          MapMode.READ_WRITE,
          -1L,
          fc.size(),
          NonWritableChannelException.class,
          IllegalArgumentException.class);

      checkException(
          fc,
          MapMode.READ_WRITE,
          0L,
          -1L,
          NonWritableChannelException.class,
          IllegalArgumentException.class);

      checkException(fc, MapMode.PRIVATE, 0L, fc.size(), NonWritableChannelException.class);

      checkException(
          fc,
          MapMode.PRIVATE,
          -1L,
          fc.size(),
          NonWritableChannelException.class,
          IllegalArgumentException.class);

      checkException(
          fc,
          MapMode.PRIVATE,
          0L,
          -1L,
          NonWritableChannelException.class,
          IllegalArgumentException.class);
    }

    // check exceptions when channel opened for write access
    try (FileChannel fc = FileChannel.open(blah.toPath(), WRITE)) {
      testExceptions(fc);

      checkException(fc, MapMode.READ_ONLY, 0L, fc.size(), NonReadableChannelException.class);

      checkException(
          fc,
          MapMode.READ_ONLY,
          -1L,
          fc.size(),
          NonReadableChannelException.class,
          IllegalArgumentException.class);

      /*
       * implementation/spec mismatch, these tests disabled for now
       */
      // checkException(fc, MapMode.READ_WRITE, 0L, fc.size(),
      //               NonWritableChannelException.class);
      // checkException(fc, MapMode.PRIVATE, 0L, fc.size(),
      //               NonWritableChannelException.class);
    }

    // check exceptions when channel opened for read and write access
    try (FileChannel fc = FileChannel.open(blah.toPath(), READ, WRITE)) {
      testExceptions(fc);
    }
  }