Wrap MessageValues in try-resources.
So that they will be recycled to reduce some GC pressure.
This commit is contained in:
parent
e8188b9564
commit
ef48c1647e
1 changed files with 18 additions and 15 deletions
|
@ -40,29 +40,32 @@ class SambaFileClient extends BaseClient implements SmbFile {
|
|||
|
||||
@Override
|
||||
public int read(ByteBuffer buffer) throws IOException {
|
||||
final MessageValues<ByteBuffer> messageValues = MessageValues.obtain();
|
||||
messageValues.setObj(buffer);
|
||||
final Message msg = mHandler.obtainMessage(READ, messageValues);
|
||||
enqueue(msg);
|
||||
return messageValues.getInt();
|
||||
try(final MessageValues<ByteBuffer> messageValues = MessageValues.obtain()) {
|
||||
messageValues.setObj(buffer);
|
||||
final Message msg = mHandler.obtainMessage(READ, messageValues);
|
||||
enqueue(msg);
|
||||
return messageValues.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int write(ByteBuffer buffer, int length) throws IOException {
|
||||
final MessageValues<ByteBuffer> messageValues = MessageValues.obtain();
|
||||
messageValues.setObj(buffer);
|
||||
final Message msg = mHandler.obtainMessage(WRITE, messageValues);
|
||||
msg.arg1 = length;
|
||||
enqueue(msg);
|
||||
return messageValues.getInt();
|
||||
try (final MessageValues<ByteBuffer> messageValues = MessageValues.obtain()) {
|
||||
messageValues.setObj(buffer);
|
||||
final Message msg = mHandler.obtainMessage(WRITE, messageValues);
|
||||
msg.arg1 = length;
|
||||
enqueue(msg);
|
||||
return messageValues.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
final MessageValues messageValues = MessageValues.obtain();
|
||||
final Message msg = mHandler.obtainMessage(CLOSE, messageValues);
|
||||
enqueue(msg);
|
||||
messageValues.checkException();
|
||||
try (final MessageValues messageValues = MessageValues.obtain()) {
|
||||
final Message msg = mHandler.obtainMessage(CLOSE, messageValues);
|
||||
enqueue(msg);
|
||||
messageValues.checkException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class SambaFileHandler extends BaseHandler {
|
||||
|
|
Loading…
Reference in a new issue