Class SynchronizedStringWriter

A thread-safe StringWriter.

Synopsis

 public final class SynchronizedStringWriter extends StringWriter {
  public SynchronizedStringWriter();
  public synchronized int hashCode();
  public synchronized boolean equals(Object obj);
  public synchronized void write(int c);
  public synchronized void write(char[] cbuf)
    throws IOException;

  public synchronized void write(char[] cbuf,
                                 int off,
                                 int len);

  public synchronized void write(String str);
  public synchronized void write(String str,
                                 int off,
                                 int len);

  public synchronized StringWriter append(CharSequence csq);
  public synchronized StringWriter append(CharSequence csq,
                                          int start,
                                          int end);

  public synchronized StringWriter append(char c);
  public synchronized String toString();
  protected void finalize()
    throws Throwable;

  public synchronized StringBuffer getBuffer();
  public synchronized void flush();
  public synchronized void close()
    throws IOException;

}

Methods inherited from java.io.StringWriter: append, close, flush, getBuffer, toString, write

Methods inherited from java.lang.Object: clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait

Inheritance Path. java.lang.Object-> java.io.Writer-> java.io.StringWriter-> org.kaiwitte.workbench.ui.model.SynchronizedStringWriter

SynchronizedStringWriter()

Synopsis: public SynchronizedStringWriter();

Create a new string writer, using the default initial string-buffer size.

append(char)

Synopsis: public StringWriter append(char c);

Parameters

c

The 16-bit character to append

return

This writer

Since

1.5

Appends the specified character to this writer.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

     out.write(c) 

append(CharSequence)

Synopsis: public StringWriter append(java.lang.CharSequence csq);

Parameters

csq

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

return

This writer

Since

1.5

Appends the specified character sequence to this writer.

An invocation of this method of the form out.append(csq) behaves in exactly the same way as the invocation

     out.write(csq.toString()) 

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

append(CharSequence, int, int)

Synopsis: public StringWriter append(java.lang.CharSequence csq, 
                                     int start, int end);

Parameters

csq

The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".

start

The index of the first character in the subsequence

end

The index of the character following the last character in the subsequence

return

This writer

Exceptions

IndexOutOfBoundsException

If start or end are negative, start is greater than end, or end is greater than csq.length()

Since

1.5

Appends a subsequence of the specified character sequence to this writer.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

     out.write(csq.subSequence(start, end).toString()) 

close()

Synopsis: public void close() throws java.io.IOException;

Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

equals(Object)

Synopsis: public boolean equals(java.lang.Object obj);

Parameters

obj

the reference object with which to compare.

return

true if this object is the same as the obj argument; false otherwise.

See Also
hashCode(), java.util.Hashtable

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.

  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.

  • For any non-null reference value x, x.equals(null) should return false.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

finalize()

Synopsis: protected void finalize() throws java.lang.Throwable;

Exceptions

Throwable

the Exception raised by this method

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

flush()

Synopsis: public void flush();

Flush the stream.

getBuffer()

Synopsis: public StringBuffer getBuffer();

Parameters

return

StringBuffer holding the current buffer value.

Return the string buffer itself.

hashCode()

Synopsis: public int hashCode();

Parameters

return

a hash code value for this object.

See Also
java.lang.Object.equals, java.util.Hashtable

Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.

  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

  • It is not required that if two objects are unequal according to the java.lang.Object.equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

toString()

Synopsis: public String toString();

Return the buffer's current value as a string.

write(char[])

Synopsis: public void write(char[] cbuf) throws java.io.IOException;

Parameters

cbuf

Array of characters to be written

Exceptions

java.io.IOException

If an I/O error occurs

Write an array of characters.

write(char[], int, int)

Synopsis: public void write(char[] cbuf, int off, int len);

Parameters

cbuf

Array of characters

off

Offset from which to start writing characters

len

Number of characters to write

Write a portion of an array of characters.

write(int)

Synopsis: public void write(int c);

Write a single character.

write(String)

Synopsis: public void write(java.lang.String str);

Write a string.

write(String, int, int)

Synopsis: public void write(java.lang.String str, int off, int len);

Parameters

str

String to be written

off

Offset from which to start writing characters

len

Number of characters to write

Write a portion of a string.