[GH-ISSUE #974] WebServiceDataTransfer exportData getBytesWritten() always return zero #230

Closed
opened 2026-03-07 20:46:30 +03:00 by kerem · 4 comments
Owner

Originally created by @vaelao on GitHub (Jul 21, 2022).
Original GitHub issue: https://github.com/dbeaver/cloudbeaver/issues/974

StreamTransferConsumer consumer = new StreamTransferConsumer() {
@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException {
super.fetchRow(session, resultSet);
if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) {
throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT,
fileSizeLimit.longValue(), getBytesWritten());
}
}
};
getBytesWritten() value always return zero.

Originally created by @vaelao on GitHub (Jul 21, 2022). Original GitHub issue: https://github.com/dbeaver/cloudbeaver/issues/974 StreamTransferConsumer consumer = new StreamTransferConsumer() { @Override public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException { super.fetchRow(session, resultSet); if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) { throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT, fileSizeLimit.longValue(), getBytesWritten()); } } }; getBytesWritten() value always return zero.
kerem 2026-03-07 20:46:30 +03:00
Author
Owner

@kseniiaguzeeva commented on GitHub (Jul 21, 2022):

Am I right that you try to export a big table from CloudBeaver? In this case please try to change the export limit. If I'm wrong, could you please tell me:

  • steps to reproduce the issue, expected and actual results;
  • your CloudBeaver version;
  • your browser version.
<!-- gh-comment-id:1191368021 --> @kseniiaguzeeva commented on GitHub (Jul 21, 2022): Am I right that you try to export a big table from CloudBeaver? In this case please try to change [the export limit](https://github.com/dbeaver/cloudbeaver/wiki/Server-configuration#resource-quotas). If I'm wrong, could you please tell me: - steps to reproduce the issue, expected and actual results; - your CloudBeaver version; - your browser version.
Author
Owner

@vaelao commented on GitHub (Jul 22, 2022):

  • reproduce the issue:
    Well, when I was testing the table data export, I see this class WebServiceDataTransfer first judged the size of the exported table data through the data stream. However,I found that the size of the data stream(bytesWritten) kept returning zero until the data transfer was completed.As shown in the code:

WebServiceDataTransfer

StreamTransferConsumer consumer = new StreamTransferConsumer() {
	@Override
	public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException {
		super.fetchRow(session, resultSet);
                // bytesWritten always return zero
		log.info("bytesWritten:" + getBytesWritten());
		if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) { 
			throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT,
					fileSizeLimit.longValue(), getBytesWritten());
		}
	} 
};
...
consumer.finishTransfer(monitor, false);

StreamTransferConsumer

protected long getBytesWritten() {
    // statStream.getBytesWritten() always return zero
    return statStream == null ? 0 : statStream.getBytesWritten();
}

StatOutputStream

public class StatOutputStream extends OutputStream {
    private final OutputStream stream;
    private long bytesWritten = 0;

    public StatOutputStream(OutputStream stream) {
        this.stream = stream;
    }

    public long getBytesWritten() {
        return bytesWritten;
    }

    @Override
    public void write(int b) throws IOException {
        stream.write(b);
        bytesWritten++;
    }

    @Override
    public void write(@NotNull byte[] b) throws IOException {
        stream.write(b);
        bytesWritten += b.length;
    }

    @Override
    public void write(@NotNull byte[] b, int off, int len) throws IOException {
        stream.write(b, off, len);
        bytesWritten += len;
    }

    @Override
    public void flush() throws IOException {
        stream.flush();
    }

    @Override
    public void close() throws IOException {
        stream.close();
    }
}
  • expected: if fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()),it should throw new DBQuotaException;
if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) { 
	throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT,
			fileSizeLimit.longValue(), getBytesWritten());
}
  • actual results: the size of bytesWritten always return zero, it can't throw new DBQuotaException;
  • CloudBeaver version: 21.3.3;
  • browser version: 21.3.3.
<!-- gh-comment-id:1192111704 --> @vaelao commented on GitHub (Jul 22, 2022): - reproduce the issue: Well, when I was testing the table data export, I see this class **WebServiceDataTransfer** first judged the size of the exported table data through the data stream. However,I found that the size of the data stream(bytesWritten) kept returning zero until the data transfer was completed.As shown in the code: WebServiceDataTransfer ``` StreamTransferConsumer consumer = new StreamTransferConsumer() { @Override public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException { super.fetchRow(session, resultSet); // bytesWritten always return zero log.info("bytesWritten:" + getBytesWritten()); if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) { throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT, fileSizeLimit.longValue(), getBytesWritten()); } } }; ... consumer.finishTransfer(monitor, false); ``` StreamTransferConsumer ``` protected long getBytesWritten() { // statStream.getBytesWritten() always return zero return statStream == null ? 0 : statStream.getBytesWritten(); } ``` StatOutputStream ``` public class StatOutputStream extends OutputStream { private final OutputStream stream; private long bytesWritten = 0; public StatOutputStream(OutputStream stream) { this.stream = stream; } public long getBytesWritten() { return bytesWritten; } @Override public void write(int b) throws IOException { stream.write(b); bytesWritten++; } @Override public void write(@NotNull byte[] b) throws IOException { stream.write(b); bytesWritten += b.length; } @Override public void write(@NotNull byte[] b, int off, int len) throws IOException { stream.write(b, off, len); bytesWritten += len; } @Override public void flush() throws IOException { stream.flush(); } @Override public void close() throws IOException { stream.close(); } } ``` - expected: if fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()),it should throw new DBQuotaException; ``` if (fileSizeLimit != null && getBytesWritten() > fileSizeLimit.longValue()) { throw new DBQuotaException("Data export quota exceeded", QUOTA_PROP_FILE_LIMIT, fileSizeLimit.longValue(), getBytesWritten()); } ``` - actual results: the size of bytesWritten always return zero, it can't throw new DBQuotaException; - CloudBeaver version: 21.3.3; - browser version: 21.3.3.
Author
Owner

@kseniiaguzeeva commented on GitHub (Jul 28, 2022):

Thank you for the explanation. We are going to investigate and fix the issue.

<!-- gh-comment-id:1198083133 --> @kseniiaguzeeva commented on GitHub (Jul 28, 2022): Thank you for the explanation. We are going to investigate and fix the issue.
Author
Owner

@kseniaguzeeva commented on GitHub (Sep 7, 2022):

The bug is fixed and available in the latest 22.2.0 release.

<!-- gh-comment-id:1239053954 --> @kseniaguzeeva commented on GitHub (Sep 7, 2022): The bug is fixed and available in the latest 22.2.0 release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cloudbeaver#230
No description provided.