What is writer in java

What is writer in java

Abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

Field Summary

Constructor Summary

Method Summary

Methods inherited from class java.lang.Object

Field Detail

lock

The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method.

Constructor Detail

Writer

Writer

Method Detail

write

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.

Читайте также:  Target blank html пример

write

write

write

write

public void write(String str, int off, int len) throws IOException

append

public Writer append(CharSequence csq) throws IOException

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

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

public Writer append(CharSequence csq, int start, int end) throws IOException

Appends a subsequence of the specified character sequence to this writer. Appendable. 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())

append

public Writer append(char c) throws IOException

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

flush

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Читайте также:  Исходный код html символы

close

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

What is writer in java

Abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

Field Summary

Constructor Summary

Method Summary

Methods declared in class java.lang.Object

Field Detail

lock

The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method.

Constructor Detail

Writer

Writer

Method Detail

nullWriter

Returns a new Writer which discards all characters. The returned stream is initially open. The stream is closed by calling the close() method. Subsequent calls to close() have no effect. While the stream is open, the append(char) , append(CharSequence) , append(CharSequence, int, int) , flush() , write(int) , write(char[]) , and write(char[], int, int) methods do nothing. After the stream has been closed, these methods all throw IOException . The object used to synchronize operations on the returned Writer is not specified.

write

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.

write

write

write

write

public void write​(String str, int off, int len) throws IOException

append

public Writer append​(CharSequence csq) throws IOException

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

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

public Writer append​(CharSequence csq, int start, int end) throws IOException

Appends a subsequence of the specified character sequence to this writer. Appendable . 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()) 

append

public Writer append​(char c) throws IOException

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

flush

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

close

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Class Writer

Abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

Field Summary

Constructor Summary

Method Summary

Methods declared in class java.lang.Object

Field Details

lock

The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method.

Constructor Details

Writer

Writer

Method Details

nullWriter

Returns a new Writer which discards all characters. The returned stream is initially open. The stream is closed by calling the close() method. Subsequent calls to close() have no effect. While the stream is open, the append(char) , append(CharSequence) , append(CharSequence, int, int) , flush() , write(int) , write(char[]) , and write(char[], int, int) methods do nothing. After the stream has been closed, these methods all throw IOException . The object used to synchronize operations on the returned Writer is not specified.

write

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.

write

write

write

write

append

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

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

Appends a subsequence of the specified character sequence to this writer. Appendable . 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()) 

append

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

flush

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

close

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Оцените статью