1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-30 10:12:06 +01:00

Increased file transfer buffer size.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3701 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-04-04 20:44:39 +00:00 committed by alex
parent 8d3bf139c6
commit a5b061d187

View file

@ -56,6 +56,11 @@ public abstract class FileTransfer {
private Exception exception; private Exception exception;
/**
* Buffer size between input and output
*/
private static final int BUFFER_SIZE = 8192;
protected FileTransfer(String peer, String streamID, protected FileTransfer(String peer, String streamID,
FileTransferNegotiator negotiator) { FileTransferNegotiator negotiator) {
this.peer = peer; this.peer = peer;
@ -196,20 +201,13 @@ public abstract class FileTransfer {
} }
protected void writeToStream(final InputStream in, final OutputStream out) protected void writeToStream(final InputStream in, final OutputStream out)
throws XMPPException { throws XMPPException
final byte[] b = new byte[1000]; {
int count; final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = 0; amountWritten = 0;
try {
count = in.read(b);
} catch (IOException e) {
throw new XMPPException("error reading from input stream", e);
}
while (count != -1 && !getStatus().equals(Status.CANCLED)) {
if (getStatus().equals(Status.CANCLED)) {
return;
}
do {
// write to the output stream // write to the output stream
try { try {
out.write(b, 0, count); out.write(b, 0, count);
@ -225,10 +223,9 @@ public abstract class FileTransfer {
} catch (IOException e) { } catch (IOException e) {
throw new XMPPException("error reading from input stream", e); throw new XMPPException("error reading from input stream", e);
} }
} } while (count != -1 && !getStatus().equals(Status.CANCLED));
// the connection was likely terminated abrubtly if these are not // the connection was likely terminated abrubtly if these are not equal
// equal
if (!getStatus().equals(Status.CANCLED) && getError() == Error.NONE if (!getStatus().equals(Status.CANCLED) && getError() == Error.NONE
&& amountWritten != fileSize) { && amountWritten != fileSize) {
setStatus(Status.ERROR); setStatus(Status.ERROR);