What is the difference between Tomcat’s BIO Connector and NIO Connector?

NIO and Comet are completely unrelated: you can mix-and-match them. Using the NIO (or APR for that matter) connector allows you to handle more requests with fewer threads due to the threading model. See http://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Connector_Comparison for a comparison between the Connectors. Comet (and Websocket) have a completely different dispatch model which requires a different application … Read more

Alternative to File.deleteOnExit() in Java NIO?

Short Answer You can’t delete arbitrary files in Java NIO, but you can use the StandardOpenOption.DELETE_ON_CLOSE when opening a new stream, which will delete the file as soon as the stream closes, either by calling .close() (including from a try-with-resources statement) or the JVM terminating. For instance: Files.newOutputStream(Paths.get(“Foo.tmp”), StandardOpenOption.DELETE_ON_CLOSE); Long Answer After a great deal … Read more

How to overwrite file via java nio writer?

You want to call the method without any OpenOption arguments. Files.write(path, content.getBytes()); From the Javadoc: The options parameter specifies how the the file is created or opened. If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, … Read more

Wrapping a ByteBuffer with an InputStream

There seem to be some bugs with the implementation referred to by Thilo, and also copy and pasted on other sites verbatim: ByteBufferBackedInputStream.read() returns a sign extended int representation of the byte it reads, which is wrong (value should be in range [-1..255]) ByteBufferBackedInputStream.read(byte[], int, int) does not return -1 when there are no bytes … Read more

When to use ** (double star) in glob syntax within JAVA

The javadoc for FileSystem#getPathMatcher() has some pretty good examples and explanations *.java Matches a path that represents a file name ending in .java *.* Matches file names containing a dot *.{java,class} Matches file names ending with .java or .class foo.? Matches file names starting with foo. and a single character extension /home/*/* Matches /home/gus/data on … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)