io.qt.core.QIODevice Maven / Gradle / Ivy
Show all versions of qtjambi Show documentation
package io.qt.core;
import io.qt.*;
/**
* The base interface class of all I/O devices in Qt
* Java wrapper for Qt class QIODevice
*/
public abstract class QIODevice extends io.qt.core.QObject
implements io.qt.core.QIODeviceBase
{
/**
* This variable stores the meta-object for the class.
*/
public static final io.qt.core.@NonNull QMetaObject staticMetaObject = io.qt.core.QMetaObject.forType(QIODevice.class);
@NativeAccess
private static final class ConcreteWrapper extends QIODevice {
@NativeAccess
private ConcreteWrapper(QPrivateConstructor p) { super(p); }
@Override
@QtUninvokable
protected int readData(java.nio.@Nullable ByteBuffer data){
return readData_native_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int readData_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
@Override
@QtUninvokable
protected int writeData(java.nio.@Nullable ByteBuffer data){
return writeData_native_const_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int writeData_native_const_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
}
/**
*
*/
public final @NonNull Signal0 aboutToClose = new Signal0();
/**
* See QIODevice:: bytesWritten(qint64)
*/
public final @NonNull Signal1 bytesWritten = new Signal1<>();
/**
* See QIODevice:: channelBytesWritten(int, qint64)
*/
public final @NonNull Signal2 channelBytesWritten = new Signal2<>();
/**
* See QIODevice:: channelReadyRead(int)
*/
public final @NonNull Signal1 channelReadyRead = new Signal1<>();
/**
* See QIODevice:: readChannelFinished()
*/
public final @NonNull Signal0 readChannelFinished = new Signal0();
/**
*
*/
public final @NonNull Signal0 readyRead = new Signal0();
/**
*
*/
public QIODevice(){
super((QPrivateConstructor)null);
initialize_native(this);
}
private native static void initialize_native(QIODevice instance);
/**
* See QIODevice:: QIODevice(QObject*)
*/
public QIODevice(io.qt.core.@Nullable QObject parent){
super((QPrivateConstructor)null);
initialize_native(this, parent);
}
private native static void initialize_native(QIODevice instance, io.qt.core.QObject parent);
/**
* See QIODevice:: commitTransaction()
*/
@QtUninvokable
public final void commitTransaction(){
commitTransaction_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native void commitTransaction_native(long __this__nativeId);
/**
* See QIODevice:: currentReadChannel()const
*/
@QtUninvokable
public final int currentReadChannel(){
return currentReadChannel_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native int currentReadChannel_native_constfct(long __this__nativeId);
/**
* See QIODevice:: currentWriteChannel()const
*/
@QtUninvokable
public final int currentWriteChannel(){
return currentWriteChannel_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native int currentWriteChannel_native_constfct(long __this__nativeId);
/**
* See QIODevice:: errorString()const
*/
@QtUninvokable
public final java.lang.@NonNull String errorString(){
return errorString_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native java.lang.String errorString_native_constfct(long __this__nativeId);
/**
*
*/
@QtUninvokable
public final java.lang.@Nullable Byte getByte(){
return getByte_native_char_ptr(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native java.lang.@Nullable Byte getByte_native_char_ptr(long __this__nativeId);
/**
*
*/
@QtUninvokable
public final boolean isOpen(){
return isOpen_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isOpen_native_constfct(long __this__nativeId);
/**
* See QIODevice:: isReadable()const
*/
@QtUninvokable
public final boolean isReadable(){
return isReadable_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isReadable_native_constfct(long __this__nativeId);
/**
* See QIODevice:: isTextModeEnabled()const
*/
@QtUninvokable
public final boolean isTextModeEnabled(){
return isTextModeEnabled_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isTextModeEnabled_native_constfct(long __this__nativeId);
/**
* See QIODevice:: isTransactionStarted()const
*/
@QtUninvokable
public final boolean isTransactionStarted(){
return isTransactionStarted_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isTransactionStarted_native_constfct(long __this__nativeId);
/**
* See QIODevice:: isWritable()const
*/
@QtUninvokable
public final boolean isWritable(){
return isWritable_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isWritable_native_constfct(long __this__nativeId);
/**
* See QIODevice:: openMode()const
*/
@QtUninvokable
public final io.qt.core.QIODeviceBase.@NonNull OpenMode openMode(){
return new io.qt.core.QIODeviceBase.OpenMode(openMode_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this)));
}
@QtUninvokable
private native int openMode_native_constfct(long __this__nativeId);
/**
* See QIODevice:: peek(char*, qint64)
*/
@QtUninvokable
public final int peek(java.nio.@Nullable ByteBuffer data){
return peek_native_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int peek_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
*
*/
@QtUninvokable
public final io.qt.core.@NonNull QByteArray peek(long maxlen){
return peek_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), maxlen);
}
@QtUninvokable
private native io.qt.core.QByteArray peek_native_qint64(long __this__nativeId, long maxlen);
/**
*
*/
@QtUninvokable
public final boolean putByte(byte c){
return putByte_native_char(QtJambi_LibraryUtilities.internal.nativeId(this), c);
}
@QtUninvokable
private native boolean putByte_native_char(long __this__nativeId, byte c);
/**
* See QIODevice:: read(char*, qint64)
*/
@QtUninvokable
public final int read(java.nio.@Nullable ByteBuffer data){
return read_native_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int read_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
*
*/
@QtUninvokable
public final io.qt.core.@NonNull QByteArray read(long maxlen){
return read_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), maxlen);
}
@QtUninvokable
private native io.qt.core.QByteArray read_native_qint64(long __this__nativeId, long maxlen);
/**
*
*/
@QtUninvokable
public final io.qt.core.@NonNull QByteArray readAll(){
return readAll_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native io.qt.core.QByteArray readAll_native(long __this__nativeId);
/**
* See QIODevice:: readChannelCount()const
*/
@QtUninvokable
public final int readChannelCount(){
return readChannelCount_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native int readChannelCount_native_constfct(long __this__nativeId);
/**
* See QIODevice:: readLine(char*, qint64)
*/
@QtUninvokable
public final int readLine(java.nio.@Nullable ByteBuffer data){
return readLine_native_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int readLine_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
* See QIODevice:: readLine(qint64)
*/
@QtUninvokable
public final io.qt.core.@NonNull QByteArray readLine(long maxlen){
return readLine_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), maxlen);
}
@QtUninvokable
private native io.qt.core.QByteArray readLine_native_qint64(long __this__nativeId, long maxlen);
/**
* See QIODevice:: rollbackTransaction()
*/
@QtUninvokable
public final void rollbackTransaction(){
rollbackTransaction_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native void rollbackTransaction_native(long __this__nativeId);
/**
* See QIODevice:: setCurrentReadChannel(int)
*/
@QtUninvokable
public final void setCurrentReadChannel(int channel){
setCurrentReadChannel_native_int(QtJambi_LibraryUtilities.internal.nativeId(this), channel);
}
@QtUninvokable
private native void setCurrentReadChannel_native_int(long __this__nativeId, int channel);
/**
* See QIODevice:: setCurrentWriteChannel(int)
*/
@QtUninvokable
public final void setCurrentWriteChannel(int channel){
setCurrentWriteChannel_native_int(QtJambi_LibraryUtilities.internal.nativeId(this), channel);
}
@QtUninvokable
private native void setCurrentWriteChannel_native_int(long __this__nativeId, int channel);
/**
* See QIODevice:: setErrorString(QString)
*/
@QtUninvokable
protected final void setErrorString(java.lang.@NonNull String errorString){
setErrorString_native_cref_QString(QtJambi_LibraryUtilities.internal.nativeId(this), errorString);
}
@QtUninvokable
private native void setErrorString_native_cref_QString(long __this__nativeId, java.lang.String errorString);
/**
* See QIODevice:: setOpenMode(QIODeviceBase::OpenMode)
*/
@QtUninvokable
protected final void setOpenMode(io.qt.core.QIODeviceBase.@NonNull OpenMode openMode){
setOpenMode_native_QIODeviceBase_OpenMode(QtJambi_LibraryUtilities.internal.nativeId(this), openMode.value());
}
@QtUninvokable
private native void setOpenMode_native_QIODeviceBase_OpenMode(long __this__nativeId, int openMode);
/**
* See QIODevice:: setTextModeEnabled(bool)
*/
@QtUninvokable
public final void setTextModeEnabled(boolean enabled){
setTextModeEnabled_native_bool(QtJambi_LibraryUtilities.internal.nativeId(this), enabled);
}
@QtUninvokable
private native void setTextModeEnabled_native_bool(long __this__nativeId, boolean enabled);
/**
*
*/
@QtUninvokable
public final long skip(long maxSize){
return skip_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), maxSize);
}
@QtUninvokable
private native long skip_native_qint64(long __this__nativeId, long maxSize);
/**
* See QIODevice:: startTransaction()
*/
@QtUninvokable
public final void startTransaction(){
startTransaction_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native void startTransaction_native(long __this__nativeId);
/**
* See QIODevice:: ungetChar(char)
*/
@QtUninvokable
public final void ungetByte(byte c){
ungetByte_native_char(QtJambi_LibraryUtilities.internal.nativeId(this), c);
}
@QtUninvokable
private native void ungetByte_native_char(long __this__nativeId, byte c);
/**
* See QIODevice:: write(QByteArray)
*/
@QtUninvokable
public final long write(io.qt.core.@NonNull QByteArray data){
return write_native_cref_QByteArray(QtJambi_LibraryUtilities.internal.nativeId(this), QtJambi_LibraryUtilities.internal.checkedNativeId(data));
}
@QtUninvokable
private native long write_native_cref_QByteArray(long __this__nativeId, long data);
/**
* See QIODevice:: write(const char*, qint64)
*/
@QtUninvokable
public final int write(java.nio.@Nullable ByteBuffer data){
return write_native_const_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int write_native_const_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
* See QIODevice:: writeChannelCount()const
*/
@QtUninvokable
public final int writeChannelCount(){
return writeChannelCount_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native int writeChannelCount_native_constfct(long __this__nativeId);
/**
*
*/
@QtUninvokable
public boolean atEnd(){
return atEnd_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean atEnd_native_constfct(long __this__nativeId);
/**
* See QIODevice:: bytesAvailable()const
*/
@QtUninvokable
public long bytesAvailable(){
return bytesAvailable_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native long bytesAvailable_native_constfct(long __this__nativeId);
/**
* See QIODevice:: bytesToWrite()const
*/
@QtUninvokable
public long bytesToWrite(){
return bytesToWrite_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native long bytesToWrite_native_constfct(long __this__nativeId);
/**
* See QIODevice:: canReadLine()const
*/
@QtUninvokable
public boolean canReadLine(){
return canReadLine_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean canReadLine_native_constfct(long __this__nativeId);
/**
*
*/
@QtUninvokable
public void close(){
close_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native void close_native(long __this__nativeId);
/**
* See QIODevice:: isSequential()const
*/
@QtUninvokable
public boolean isSequential(){
return isSequential_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean isSequential_native_constfct(long __this__nativeId);
/**
* See QIODevice:: open(QIODeviceBase::OpenMode)
*/
@QtUninvokable
public boolean open(io.qt.core.QIODeviceBase.@NonNull OpenMode mode){
return open_native_QIODeviceBase_OpenMode(QtJambi_LibraryUtilities.internal.nativeId(this), mode.value());
}
@QtUninvokable
private native boolean open_native_QIODeviceBase_OpenMode(long __this__nativeId, int mode);
/**
*
*/
@QtUninvokable
public long pos(){
return pos_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native long pos_native_constfct(long __this__nativeId);
/**
* See QIODevice:: readData(char*, qint64)
*/
@QtUninvokable
protected abstract int readData(java.nio.@Nullable ByteBuffer data);
@QtUninvokable
private native int readData_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
* See QIODevice:: readLineData(char*, qint64)
*/
@QtUninvokable
protected int readLineData(java.nio.@Nullable ByteBuffer data){
return readLineData_native_char_ptr_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), data);
}
@QtUninvokable
private native int readLineData_native_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
*
*/
@QtUninvokable
public boolean reset(){
return reset_native(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native boolean reset_native(long __this__nativeId);
/**
*
*/
@QtUninvokable
public boolean seek(long pos){
return seek_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), pos);
}
@QtUninvokable
private native boolean seek_native_qint64(long __this__nativeId, long pos);
/**
*
*/
@QtUninvokable
public long size(){
return size_native_constfct(QtJambi_LibraryUtilities.internal.nativeId(this));
}
@QtUninvokable
private native long size_native_constfct(long __this__nativeId);
/**
* See QIODevice:: skipData(qint64)
*/
@QtUninvokable
protected long skipData(long maxSize){
return skipData_native_qint64(QtJambi_LibraryUtilities.internal.nativeId(this), maxSize);
}
@QtUninvokable
private native long skipData_native_qint64(long __this__nativeId, long maxSize);
/**
* See QIODevice:: waitForBytesWritten(int)
*/
@QtUninvokable
public boolean waitForBytesWritten(int msecs){
return waitForBytesWritten_native_int(QtJambi_LibraryUtilities.internal.nativeId(this), msecs);
}
@QtUninvokable
private native boolean waitForBytesWritten_native_int(long __this__nativeId, int msecs);
/**
* See QIODevice:: waitForReadyRead(int)
*/
@QtUninvokable
public boolean waitForReadyRead(int msecs){
return waitForReadyRead_native_int(QtJambi_LibraryUtilities.internal.nativeId(this), msecs);
}
@QtUninvokable
private native boolean waitForReadyRead_native_int(long __this__nativeId, int msecs);
/**
* See QIODevice:: writeData(const char*, qint64)
*/
@QtUninvokable
protected abstract int writeData(java.nio.@Nullable ByteBuffer data);
@QtUninvokable
private native int writeData_native_const_char_ptr_qint64(long __this__nativeId, java.nio.ByteBuffer data);
/**
* Constructor for internal use only.
* @param p expected to be null
.
* @hidden
*/
@NativeAccess
protected QIODevice(QPrivateConstructor p) { super(p); }
/**
* Constructor for internal use only.
* It is not allowed to call the declarative constructor from inside Java.
* @hidden
*/
@NativeAccess
protected QIODevice(QDeclarativeConstructor constructor) {
super((QPrivateConstructor)null);
initialize_native(this, constructor);
}
@QtUninvokable
private static native void initialize_native(QIODevice instance, QDeclarativeConstructor constructor);
// TEMPLATE - QIODevice_toStream - START
/**
* @deprecated use {@link #fromBuffer(java.nio.Buffer)} instead.
*/
@Deprecated
public static @NonNull QIODevice fromDirectBuffer(java.nio.@NonNull Buffer buffer){
return fromBuffer(buffer);
}
/**
* Creates QIODevice from direct buffer. The new I/O device is not open.
* @param buffer
* @return new new QIODevice or null if no direct buffer
*/
public native static @NonNull QIODevice fromBuffer(java.nio.@NonNull Buffer buffer);
/**
* Creates a new InputStream for reading from given QIODevice.
* If the given device is open for reading it remains open after closing the InputStream.
* If the give device is still not open the InputStream opens it for reading and closes it finally.
* If the device cannot be opened for reading {@code null} is returned.
*
* @param device
* @return new InputStream
*/
public static java.io.@Nullable InputStream toInputStream(@StrictNonNull QIODevice device) {
boolean closeFinally;
if((closeFinally = !device.isOpen()))
device.open(OpenModeFlag.ReadOnly);
if(device.isOpen() && device.isReadable()) {
return new java.io.InputStream(){
private final byte[] buffer1 = {0};
@Override
public int read() throws java.io.IOException {
device.read(buffer1);
return buffer1[0];
}
@Override
public int read(byte[] b) throws java.io.IOException {
return device.read(b);
}
@Override
public int read(byte b[], int off, int len) throws java.io.IOException {
return device.read(b, off, len);
}
@Override
public void close() throws java.io.IOException {
if(closeFinally)
device.close();
}
@Override
public int available() throws java.io.IOException {
return (int)device.bytesAvailable();
}
};
}
return null;
}
/**
* Creates a new OutputStream for writing to given QIODevice.
* If the given device is open for writing it remains open after closing the OutputStream.
* If the give device is still not open the OutputStream opens it for writing and closes it finally.
* If the device cannot be opened for writing {@code null} is returned.
*
* @param device
* @return new OutputStream
*/
public static java.io.@Nullable OutputStream toOutputStream(@StrictNonNull QIODevice device) {
boolean closeFinally;
if((closeFinally = !device.isOpen()))
device.open(OpenModeFlag.WriteOnly);
if(device.isOpen() && device.isWritable()) {
return new java.io.OutputStream(){
private final byte[] buffer1 = {0};
@Override
public void write(int b) throws java.io.IOException {
buffer1[0] = (byte)b;
device.write(buffer1);
}
@Override
public void write(byte[] b) throws java.io.IOException {
device.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws java.io.IOException {
device.write(b, off, len);
}
@Override
public void close() throws java.io.IOException {
if(closeFinally)
device.close();
}
};
}
return null;
}
/**
* Creates a new WritableByteChannel for writing to given QIODevice.
* If the given device is open for writing it remains open after closing the Channel.
* If the give device is still not open the Channel opens it for writing and closes it finally.
* If the device cannot be opened for writing {@code null} is returned.
*
* @param device
* @return new WritableByteChannel
*/
public static java.nio.channels.@Nullable WritableByteChannel toWritableByteChannel(@StrictNonNull QIODevice device) {
boolean closeFinally;
if((closeFinally = !device.isOpen()))
device.open(OpenModeFlag.WriteOnly);
if(device.isOpen() && device.isWritable()) {
return new java.nio.channels.WritableByteChannel(){
@Override
public void close() throws java.io.IOException {
if(closeFinally)
device.close();
}
@Override
public boolean isOpen() {
return device.isOpen();
}
@Override
public int write(java.nio.ByteBuffer src) {
return device.write(src);
}
};
}
return null;
}
/**
* Creates a new ReadableByteChannel for reading from given QIODevice.
* If the given device is open for reading it remains open after closing the Channel.
* If the give device is still not open the Channel opens it for reading and closes it finally.
* If the device cannot be opened for reading {@code null} is returned.
*
* @param device
* @return new ReadableByteChannel
*/
public static java.nio.channels.@Nullable ReadableByteChannel toReadableByteChannel(@StrictNonNull QIODevice device) {
boolean closeFinally;
if((closeFinally = !device.isOpen()))
device.open(OpenModeFlag.ReadOnly);
if(device.isOpen() && device.isReadable()) {
return new java.nio.channels.ReadableByteChannel(){
@Override
public void close() throws java.io.IOException {
if(closeFinally)
device.close();
}
@Override
public boolean isOpen() {
return device.isOpen();
}
@Override
public int read(java.nio.ByteBuffer src) {
return device.read(src);
}
};
}
return null;
}
/**
* Creates a new open QIODevice for reading from given InputStream
* @param stream
* @return new open read-only QIODevice
*/
public static @NonNull QIODevice fromInputStream(java.io.@StrictNonNull InputStream stream) {
java.util.Objects.requireNonNull(stream);
return new QIODevice() {
{
setOpenMode(QIODevice.OpenModeFlag.ReadOnly);
}
@Override
public long bytesAvailable() {
try {
return stream.available();
} catch (java.io.IOException e) {
return 0;
}
}
@Override
public boolean canReadLine() {
return false;
}
@Override
public void close() {
try {
stream.close();
} catch (java.io.IOException e) {
}
super.close();
}
@Override
public boolean isSequential() {
return true;
}
@Override
public boolean open(OpenMode mode) {
if(mode.value()==OpenModeFlag.ReadOnly.value())
return super.open(mode);
else return false;
}
@Override
public long pos() {
return super.pos();
}
@Override
protected int readLineData(java.nio.ByteBuffer data) {
return 0;
}
@Override
public boolean reset() {
try {
stream.reset();
} catch (java.io.IOException e) {
return false;
}
return super.reset();
}
@Override
public boolean seek(long pos) {
return false;
}
@Override
protected int writeData(java.nio.ByteBuffer data) {
return 0;
}
@Override
protected int readData(java.nio.ByteBuffer data) {
if(data==null)
return 0;
try {
if(data.hasArray()) {
return stream.read(data.array(), data.position(), data.limit()-data.position());
}else if(data.capacity()>data.position()){
int initialPos = data.position();
int nextByte = stream.read();
while(nextByte>=0) {
data.put((byte)nextByte);
if(data.capacity()==data.position())
break;
nextByte = stream.read();
}
return data.position()-initialPos;
}
} catch (java.io.IOException e) {
}
return -1;
}
@Override
protected long skipData(long maxSize) {
try {
stream.skip(maxSize);
} catch (java.io.IOException e) {
return 0;
}
return super.skipData(maxSize);
}
};
}
/**
* Creates a new open QIODevice for writing to given InputStream
* @param stream
* @return new open write-only QIODevice
*/
public static @NonNull QIODevice fromOutputStream(java.io.@StrictNonNull OutputStream stream) {
java.util.Objects.requireNonNull(stream);
return new QIODevice() {
{
setOpenMode(QIODevice.OpenModeFlag.WriteOnly);
}
@Override
public long bytesAvailable() {
return 0;
}
@Override
public boolean canReadLine() {
return false;
}
@Override
public void close() {
try {
stream.close();
} catch (java.io.IOException e) {
}
super.close();
}
@Override
public boolean isSequential() {
return true;
}
@Override
public boolean open(OpenMode mode) {
if(mode.value()==OpenModeFlag.WriteOnly.value())
return super.open(mode);
else return false;
}
@Override
protected int readLineData(java.nio.ByteBuffer data) {
return 0;
}
@Override
public boolean reset() {
return false;
}
@Override
public boolean seek(long pos) {
return false;
}
@Override
public long size() {
return super.size();
}
@Override
protected int writeData(java.nio.ByteBuffer data) {
if(data==null)
return 0;
try {
if(data.hasArray()) {
stream.write(data.array(), data.position(), data.limit()-data.position());
return data.limit()-data.position();
}else{
int initialPos = data.position();
while(data.limit()>data.position()) {
int nextByte = data.get();
stream.write(nextByte);
}
return data.position()-initialPos;
}
} catch (java.io.IOException e) {
}
return -1;
}
@Override
protected int readData(java.nio.ByteBuffer data) {
return 0;
}
@Override
protected long skipData(long maxSize) {
return 0;
}
};
}
/**
* Creates a new open QIODevice for reading from given Channel
* @param channel
* @return new open read and/or write QIODevice
*/
public static @NonNull QIODevice fromChannel(java.nio.channels.@StrictNonNull Channel channel) {
return new QIODevice() {
final java.nio.channels.ReadableByteChannel rchannel;
final java.nio.channels.WritableByteChannel wchannel;
{
if(channel instanceof java.nio.channels.ReadableByteChannel) {
rchannel = (java.nio.channels.ReadableByteChannel)channel;
if(channel instanceof java.nio.channels.WritableByteChannel) {
wchannel = (java.nio.channels.WritableByteChannel)channel;
setOpenMode(QIODevice.OpenModeFlag.ReadWrite);
}else {
wchannel = null;
setOpenMode(QIODevice.OpenModeFlag.ReadOnly);
}
}else if(channel instanceof java.nio.channels.WritableByteChannel) {
wchannel = (java.nio.channels.WritableByteChannel)channel;
rchannel = null;
setOpenMode(QIODevice.OpenModeFlag.WriteOnly);
}else {
wchannel = null;
rchannel = null;
}
}
@Override
public boolean canReadLine() {
return false;
}
@Override
public void close() {
try {
channel.close();
} catch (java.io.IOException e) {
}
super.close();
}
@Override
public boolean isSequential() {
return true;
}
@Override
public boolean open(OpenMode mode) {
if(channel.isOpen() && openMode().testFlags(mode))
return super.open(mode);
else return false;
}
@Override
protected int readLineData(java.nio.ByteBuffer data) {
return 0;
}
@Override
public boolean seek(long pos) {
return false;
}
@Override
protected int writeData(java.nio.ByteBuffer data) {
if(wchannel!=null) {
if(data==null)
return 0;
try {
return wchannel.write(data);
} catch (java.io.IOException e) {
}
}
return -1;
}
@Override
protected int readData(java.nio.ByteBuffer data) {
if(rchannel!=null) {
if(data==null)
return 0;
try {
return rchannel.read(data);
} catch (java.io.IOException e) {
}
}
return -1;
}
@Override
protected long skipData(long maxSize) {
return 0;
}
};
}
// TEMPLATE - QIODevice_toStream - END
/**
* Overloaded function for {@link #peek(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int peek(byte[] data, int offsetOfData, int maxlen) {
return peek(data==null ? null : java.nio.ByteBuffer.wrap(data, offsetOfData, maxlen));
}
/**
* Overloaded function for {@link #peek(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int peek(byte[] data) {
return peek(data==null ? null : java.nio.ByteBuffer.wrap(data));
}
/**
* Overloaded function for {@link #read(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int read(byte[] data, int offsetOfData, int maxlen) {
return read(data==null ? null : java.nio.ByteBuffer.wrap(data, offsetOfData, maxlen));
}
/**
* Overloaded function for {@link #read(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int read(byte[] data) {
return read(data==null ? null : java.nio.ByteBuffer.wrap(data));
}
/**
* Overloaded function for {@link #readLine(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int readLine(byte[] data, int offsetOfData, int maxlen) {
return readLine(data==null ? null : java.nio.ByteBuffer.wrap(data, offsetOfData, maxlen));
}
/**
* Overloaded function for {@link #readLine(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int readLine(byte[] data) {
return readLine(data==null ? null : java.nio.ByteBuffer.wrap(data));
}
/**
* Overloaded function for {@link #readLine(long)}
* with maxlen = 0
.
*/
@QtUninvokable
public final io.qt.core.@NonNull QByteArray readLine() {
return readLine((long)0);
}
/**
* Overloaded function for {@link #setOpenMode(io.qt.core.QIODeviceBase.OpenMode)}.
*/
@QtUninvokable
protected final void setOpenMode(io.qt.core.QIODeviceBase.@NonNull OpenModeFlag @NonNull... openMode) {
setOpenMode(new io.qt.core.QIODeviceBase.OpenMode(openMode));
}
/**
* Overloaded function for {@link #write(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int write(byte[] data, int offsetOfData, int len) {
return write(data==null ? null : java.nio.ByteBuffer.wrap(data, offsetOfData, len));
}
/**
* Overloaded function for {@link #write(java.nio.ByteBuffer)}.
*/
@QtUninvokable
public final int write(byte[] data) {
return write(data==null ? null : java.nio.ByteBuffer.wrap(data));
}
/**
* Overloaded function for {@link #open(io.qt.core.QIODeviceBase.OpenMode)}.
*/
@QtUninvokable
public final boolean open(io.qt.core.QIODeviceBase.@NonNull OpenModeFlag @NonNull... mode) {
return open(new io.qt.core.QIODeviceBase.OpenMode(mode));
}
}