Thnaks Niall and Jukka for your awnsers.
-----Niall Pemberton <[email protected]> schrieb: -----
>Do you mean this:
>http://developers.sun.com/mobility/apis/articles/fileconnection/
My term "file connection" was maybe misleading.
>public void showFile(String fileName)
Where is the connection closed?
With my suggestion the method would look like:
public static void showFile(final String fileName) throws IOException
{
InputStreamHandler ish =
new InputStreamHandler()
{
@Override
public void read(InputStream is) throws IOException
{
byte b[] = new byte[1024];
int length = is.read(b, 0, 1024);
System.out.println
("Content of "+fileName + ": "+ new String(b, 0, length));
}
};
IOUtils.read(fileName, ish);
}
==> No opening, no closing
-----Jukka Zitting <[email protected]> schrieb: -----
>OK, I see what you're after. Not sure though if there can be any
>clean API (i.e. one that's less verbose than a "open(); try { ... }
>finally { close(); }" block) for that without language extensions.
My suggestion does not need any language extensions.
>The best solutions I've seen are the automatic resource management
>blocks [1] proposed for Java 7 and the @Cleanup annotation [2]
>from Project Lombok.
Thanks for the link to the Project Lombok, there are some nice ideas there
I had myself. With the @Cleanup annotation opening is done and the closing
is moved somewhere else. I wouldn't prefer this, even when the closing is
just one annotation.
Sebastian Petzelberger
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]