Slow readng tzdb.dat
Dr Heinz M. Kabutz
heinz at javaspecialists.eu
Wed Oct 9 20:45:39 UTC 2013
Tom Hawtin wrote:
> On 09/10/2013 19:00, Dr Heinz M. Kabutz wrote:
>
>> That way, the resources are closed in the reverse order in which they
>> are opened and an exception in the middle of the creation chain does not
>> prevent the earlier resources from being closed.
>
> But there is only one resource.
>
> File tzdb = new File(libDir, "tzdb.dat");
> try (InputStream rawIn = new FileInputStream(tzdb)) {
> DataInputStream dis = new DataInputStream(
> new BufferedInputStream(rawIn, 32000)
> );
But you've written it slightly differently from the original
try (DataInputStream dis = new DataInputStream(
new FileInputStream(new File(libDir, "tzdb.dat")))) {
Your code is also fine, as it isolates the resource that should be
closed should something go wrong during the initialization of the
DataInputStream / BufferedInputStream. Either of our solutions would be
good and it would just be a matter of how you'd like to scope the
various local variables.
More information about the core-libs-dev
mailing list