The Artima Developer Community
Sponsored Link

Java Buzz Forum
Exception When Writing To A Full Disk? Not In Java!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Janek Schwarz

Posts: 95
Nickname: jschwarz
Registered: Nov, 2004

Janek Schwarz is a software developer specialized in client-side Java technologies
Exception When Writing To A Full Disk? Not In Java! Posted: Dec 22, 2004 12:48 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Janek Schwarz.
Original Post: Exception When Writing To A Full Disk? Not In Java!
Feed Title: The Wannabe Java Rockstar
Feed URL: http://weblog.janek.org/Archive/Categories/javablogs.rss.xml
Feed Description: The Wannabe Java Rockstar: Janek's weblog where all posts go to Eleven
Latest Java Buzz Posts
Latest Java Buzz Posts by Janek Schwarz
Latest Posts From The Wannabe Java Rockstar

Advertisement

Have you ever hoped to get an exception when writing to a full disk in Java? Get ready to be disappointed. Execute this code on a full disk (on Linux/Unix, you can simulate it with hard quota):

FileOutputStream ostream = new FileOutputStream("out");
ostream.write
("hello".getBytes());
ostream.close
();

No exception is thrown. All you get is a zero-byte-sized file. I don't know about you, but this is not what I expected.

After hours of googling and searching the bug parade, I found a workaround based on FileDescriptor. Every FileOutputStream has an associated file descriptor. With it's sync()-Method, one can force all system buffers to synchronize with the underlying device. The following code -- executed on a full disk -- raises a SyncFailedException:

FileOutputStream ostream = new FileOutputStream("out");
ostream.write
("hello".getBytes());
ostream.getFD
().sync();
ostream.close
();

I don't know the performance implications yet. But I'd rather suffer from a small performance loss than from data loss.

One thing, though, I have to admit: even if it makes my software look bad, bugs like 4338871 on bug parade have a certain beauty.

 

Read: Exception When Writing To A Full Disk? Not In Java!

Topic: Creating Mac OS X plugins in Python Previous Topic   Next Topic Topic: Lucene in Action eBook

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use