Interface TransactionalWriter
-
- All Superinterfaces:
- AutoCloseable, Closeable, IOTransactional, Transactional, VWriter
A transactional text writer.This interface defines two methods that terminate a transactional writing operation. These methods change the state of the transactional writer to
terminated
. In theterminated
state, invocations of these methods have no effect and invocations of writing operations throw anIllegalStateException
.The terminating methods are
commit()
andabort()
. Thecommit
method must be called after the intended contents have been written to make the contents available, for example, as a new file. Otherwise, theabort
method must be called, both to ensure that temporary resources are released and to ensure that a subsequent invocation ofcommit()
, even by accident, has no effect.The above description means that one may call
commit()
after callingabort()
or callabort()
after callingcommit()
; in either case, the second method invocation will have no effect. Thus, it is possible and convenient to callcommit()
at the end of atry
body and callabort()
in afinally
clause of the sametry
statement. Even more conveniently, if the transactional writer is created and used within a try-with-resources statement, no explicit invocation ofabort()
is required, because it will be called implicitly (asclose()
is defined to callabort()
).
-
-
Methods Modifier and Type Method and Description abort This method has no effect if the writer has already been committed or aborted.close The close method is defined to invoke the abort method.commit This method has no effect if the writer has already been committed or aborted.flush newLine write write writeln writeln
-