All posts tagged with 'Java'

Weird java generics…

07-Feb-08

Generics are not totally bad but one can write really creepy things: final FutureTask<Collection<LeitungsachseTK25>[]> ft = new FutureTask<Collection<LeitungsachseTK25>[]>( new Callable<Collection<LeitungsachseTK25>[]>() { public Collection<LeitungsachseTK25>[] call() throws Exception {final FutureTask<Collection<LeitungsachseTK25>[]> ft = new FutureTask<Collection<LeitungsachseTK25>[]>( new Callable<Collection<LeitungsachseTK25>[]>() { public Collection<LeitungsachseTK25>[] call() throws Exception { Seems like XML and Java finally married… 😉

Read the complete article »

A fistfull of readers

23-Oct-07

After presenting a working InputStream on a ByteBuffer, i have to more readers for you out there. First, the StringBufferReader to efficient read data from a StringBuffer. One can use new java.io.StringReader(sb.toString()) but that would convert the whole StringBuffer (sb) to a string, loosing a whole lotta memory if the string is just big enough. […]

Read the complete article »

Java: Creating a Stream on a ByteBuffer

18-Oct-07

This example is plain wrong. The InputStream will cause an endless loop as it always returns a value >= 0. Working code as follows: private static InputStream _newInputStream(final ByteBuffer buf) { return new InputStream() { public synchronized int read() throws IOException { return buf.hasRemaining() ? buf.get() : -1; }   public synchronized int read(byte[] bytes, […]

Read the complete article »

JDBC: Get autogenerated keys on a Oracle DB

09-Oct-07

With the current and latest Oracle JDBC Drivers it’s possible to retrieve one automatically generated key based on a sequence or any other arbitrary value (autogenerated-keys or identity columns in other databases). Certainly it isn’t as simple as just use using Statement.html#getGeneratedKeys() as it simply returns an emtpy resultset. After browsing around, i saw that […]

Read the complete article »