@Override
public void close() throws IOException {
ceph.debug("CephOutputStream.close:enter", ceph.TRACE);
- if (closed) {
- throw new IOException("Stream closed");
- }
-
- int result = ceph.ceph_close(fileHandle);
- closed = true;
- if (result != 0) {
- throw new IOException("Close somehow failed!"
- + "Don't try and use this stream again, though");
- }
- ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
- }
+ if (!closed) {
+ int result = ceph.ceph_close(fileHandle);
+ closed = true;
+ if (result != 0) {
+ throw new IOException("Close somehow failed!"
+ + "Don't try and use this stream again, though");
+ }
+ ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
+ }
+ }
}
*/
@Override
public synchronized void flush() throws IOException {
- if (closed) {
- throw new IOException("Stream closed");
+ if (!closed) {
+ if (bufUsed == 0) return;
+ int result = ceph.ceph_write(fileHandle, buffer, 0, bufUsed);
+ if (result < 0) {
+ throw new IOException("CephOutputStream.write: Write of "
+ + bufUsed + "bytes to fd "
+ + fileHandle + " failed");
+ }
+ if (result != bufUsed) {
+ throw new IOException("CephOutputStream.write: Write of " + bufUsed
+ + "bytes to fd " + fileHandle
+ + "was incomplete: only " + result + " of "
+ + bufUsed + " bytes were written.");
+ }
+ return;
}
- if (bufUsed == 0) return;
- int result = ceph.ceph_write(fileHandle, buffer, 0, bufUsed);
- if (result < 0) {
- throw new IOException("CephOutputStream.write: Write of "
- + bufUsed + "bytes to fd "
- + fileHandle + " failed");
- }
- if (result != bufUsed) {
- throw new IOException("CephOutputStream.write: Write of " + bufUsed
- + "bytes to fd " + fileHandle
- + "was incomplete: only " + result + " of "
- + bufUsed + " bytes were written.");
- }
- return;
}
/**
@Override
public synchronized void close() throws IOException {
ceph.debug("CephOutputStream.close:enter", ceph.TRACE);
- if (closed) {
- throw new IOException("Stream already closed");
- }
- flush();
- int result = ceph.ceph_close(fileHandle);
- if (result != 0) {
- throw new IOException("Close failed!");
- }
-
- closed = true;
- ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
- }
-
+ if (!closed) {
+ flush();
+ int result = ceph.ceph_close(fileHandle);
+ if (result != 0) {
+ throw new IOException("Close failed!");
+ }
+
+ closed = true;
+ ceph.debug("CephOutputStream.close:exit", ceph.TRACE);
+ }
+ }
}