
org.glassfish.grizzly.streams.StreamWriter Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.grizzly.streams;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.GrizzlyFuture;
import org.glassfish.grizzly.Transformer;
/**
* Write the primitive Java types and arrays of primitives to some data sink. This may include internal buffering for
* efficiency reasons.
*
* Note, that StreamWriter implementation may not be thread-safe.
*
* @author Ken Cavanaugh
* @author Alexey Stashok
*/
public interface StreamWriter extends Stream {
/**
* Returns true, if StreamReader has been closed, or false otherwise.
*
* @return true, if StreamReader has been closed, or false otherwise.
*/
boolean isClosed();
/**
* Make sure that all data that has been written is flushed from the stream to its destination.
*/
GrizzlyFuture flush() throws IOException;
/**
* Make sure that all data that has been written is flushed from the stream to its destination.
*/
GrizzlyFuture flush(CompletionHandler completionHandler) throws IOException;
/**
* Close the {@link StreamWriter} and make sure all data was flushed.
*/
GrizzlyFuture close(CompletionHandler completionHandler) throws IOException;
/**
* Write the boolean value to the StreamWriter.
*
* @param data boolean value.
* @throws java.io.IOException
*/
void writeBoolean(boolean data) throws IOException;
/**
* Write the byte value to the StreamWriter.
*
* @param data byte value.
* @throws java.io.IOException
*/
void writeByte(byte data) throws IOException;
/**
* Write the char value to the StreamWriter.
*
* @param data char value.
* @throws java.io.IOException
*/
void writeChar(char data) throws IOException;
/**
* Write the short value to the StreamWriter.
*
* @param data short value.
* @throws java.io.IOException
*/
void writeShort(short data) throws IOException;
/**
* Write the int value to the StreamWriter.
*
* @param data int value.
* @throws java.io.IOException
*/
void writeInt(int data) throws IOException;
/**
* Write the long value to the StreamWriter.
*
* @param data long value.
* @throws java.io.IOException
*/
void writeLong(long data) throws IOException;
/**
* Write the float value to the StreamWriter.
*
* @param data float value.
* @throws java.io.IOException
*/
void writeFloat(float data) throws IOException;
/**
* Write the double value to the StreamWriter.
*
* @param data double value.
* @throws java.io.IOException
*/
void writeDouble(double data) throws IOException;
/**
* Write the array of boolean values to the StreamWriter.
*
* @param data array of boolean values.
* @throws java.io.IOException
*/
void writeBooleanArray(final boolean[] data) throws IOException;
/**
* Write the array of byte values to the StreamWriter.
*
* @param data array of byte values.
* @throws java.io.IOException
*/
void writeByteArray(final byte[] data) throws IOException;
/**
* Write the part of array of byte values to the StreamWriter, using specific offset and length
* values.
*
* @param data array of byte values.
* @param offset array offset to start from.
* @param length number of bytes to write.
*
* @throws java.io.IOException
*/
void writeByteArray(final byte[] data, int offset, int length) throws IOException;
/**
* Write the array of char values to the StreamWriter.
*
* @param data array of char values.
* @throws java.io.IOException
*/
void writeCharArray(final char[] data) throws IOException;
/**
* Write the array of short values to the StreamWriter.
*
* @param data array of short values.
* @throws java.io.IOException
*/
void writeShortArray(short[] data) throws IOException;
/**
* Write the array of int values to the StreamWriter.
*
* @param data array of int values.
* @throws java.io.IOException
*/
void writeIntArray(int[] data) throws IOException;
/**
* Write the array of long values to the StreamWriter.
*
* @param data array of long values.
* @throws java.io.IOException
*/
void writeLongArray(long[] data) throws IOException;
/**
* Write the array of float values to the StreamWriter.
*
* @param data array of float values.
* @throws java.io.IOException
*/
void writeFloatArray(float[] data) throws IOException;
/**
* Write the array of double values to the StreamWriter.
*
* @param data array of double values.
* @throws java.io.IOException
*/
void writeDoubleArray(double[] data) throws IOException;
/**
* Write the {@link Buffer} to the StreamWriter.
*
* @param buffer {@link Buffer}.
*
* @throws java.io.IOException
*/
void writeBuffer(Buffer buffer) throws IOException;
GrizzlyFuture encode(Transformer encoder, E object) throws IOException;
GrizzlyFuture encode(Transformer encoder, E object, CompletionHandler completionHandler) throws IOException;
/**
* Get the {@link Connection} this StreamWriter belongs to.
*
* @return the {@link Connection} this StreamWriter belongs to.
*/
@Override
Connection getConnection();
/**
* Get the timeout for StreamWriter I/O operations.
*
* @param timeunit timeout unit {@link TimeUnit}.
* @return the timeout for StreamWriter I/O operations.
*/
long getTimeout(TimeUnit timeunit);
/**
* Set the timeout for StreamWriter I/O operations.
*
* @param timeout the timeout for StreamWriter I/O operations.
* @param timeunit timeout unit {@link TimeUnit}.
*/
void setTimeout(long timeout, TimeUnit timeunit);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy