Examples of FileDescriptor


Examples of java.io.FileDescriptor

   * "Too many open files" if we leaked fds using this access pattern.
   */
  @Test
  public void testFDDoesntLeak() throws IOException {
    for (int i = 0; i < 10000; i++) {
      FileDescriptor fd = NativeIO.open(
        new File(TEST_DIR, "testNoFdLeak").getAbsolutePath(),
        NativeIO.O_WRONLY | NativeIO.O_CREAT, 0700);
      assertNotNull(true);
      assertTrue(fd.valid());
      FileOutputStream fos = new FileOutputStream(fd);
      fos.write("foo".getBytes());
      fos.close();
    }
  }
View Full Code Here

Examples of java.io.FileDescriptor

    if (skipSecurity) {
      return insecureCreateForWrite(f, permissions);
    } else {
      // Use the native wrapper around open(2)
      try {
        FileDescriptor fd = NativeIO.open(f.getAbsolutePath(),
          NativeIO.O_WRONLY | NativeIO.O_CREAT | NativeIO.O_EXCL,
          permissions);
        return new FileOutputStream(fd);
      } catch (NativeIOException nioe) {
        if (nioe.getErrno() == Errno.EEXIST) {
View Full Code Here

Examples of java.io.FileDescriptor

     * Invokes <code>getFD().sync()</code> on the underlying
     * <code>RandomAccessFile</code>.
     */
    public void flush() throws IOException {
  // Fix: 4636212.  When this FIleDescriptor is not valid, do nothing.
  FileDescriptor fd = file.getFD();
        if(fd.valid())
      fd.sync();
    }
View Full Code Here

Examples of java.io.FileDescriptor

  public void test (TestHarness harness)
  {
   try {
      FileOutputStream fos = new FileOutputStream("tmpfile");
      try {
        FileDescriptor fd = fos.getFD();
        harness.check(fd.valid(), "valid()");
      try {
      fd.sync();
      harness.check(true, "sync()");
    }
    catch (SyncFailedException e) {
      harness.debug(e);
      harness.fail("SyncFailedException thrown");
View Full Code Here

Examples of java.io.FileDescriptor

     * @tests java.io.FileOutputStream#write(byte[], int, int)
     */
    public void test_write$BII3() throws IOException {
        // Regression for HARMONY-834
        // no exception expected
        new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
    }
View Full Code Here

Examples of java.io.FileDescriptor

  /**
   * @tests java.io.FileDescriptor#FileDescriptor()
   */
  public void test_Constructor() {
    // Test for method java.io.FileDescriptor()
    FileDescriptor fd = new FileDescriptor();
    assertTrue("Failed to create FileDescriptor",
        fd instanceof FileDescriptor);
  }
View Full Code Here

Examples of java.io.FileDescriptor

        f = new File(System.getProperty("user.dir"), "fd" + platformId + ".tst");
        f.delete();
        fos = new FileOutputStream(f.getPath());
        fos.write("Test String".getBytes());
        fis = new FileInputStream(f.getPath());
        FileDescriptor fd = fos.getFD();
        fd.sync();
        int length = "Test String".length();
        assertEquals("Bytes were not written after sync", length, fis
                .available());
       
        // Regression test for Harmony-1494
        fd = fis.getFD();
        fd.sync();
        assertEquals("Bytes were not written after sync", length, fis
                .available());
       
        RandomAccessFile raf = new RandomAccessFile(f, "r");
        fd = raf.getFD();
        fd.sync();
        raf.close();
  }
View Full Code Here

Examples of java.io.FileDescriptor

    try {
      f = new File(System.getProperty("user.dir"), "fd.tst");
      f.delete();
      os = new BufferedOutputStream(fos = new FileOutputStream(f
          .getPath()), 4096);
      FileDescriptor fd = fos.getFD();
      assertTrue("Valid fd returned false", fd.valid());
      os.close();
      assertTrue("Invalid fd returned true", !fd.valid());
    } catch (Exception e) {
      fail("Exception during test : " + e.getMessage());
    }

  }
View Full Code Here

Examples of java.io.FileDescriptor

     * @tests java.io.FileOutputStream#write(byte[], int, int)
     */
    public void test_write$BII3() throws Exception {
        // Regression for HARMONY-834
        //no exception expected
        new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
    }
View Full Code Here

Examples of java.io.FileDescriptor

     * Constructor
     */
    public ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
        super(sp);
        status = SERVER_STATUS_OPEN;
        fd = new FileDescriptor();
        Platform.getNetworkSystem().createServerStreamSocket(fd,
                NetUtil.preferIPv4Stack());
        impl = SocketImplProvider.getServerSocketImpl(fd);
        socket = new ServerSocketAdapter(impl, this);
    }
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.