Skip to content

Commit b1c9caa

Browse files
committed
Make reset() returns the old resource
1 parent ebb2c18 commit b1c9caa

8 files changed

Lines changed: 32 additions & 8 deletions

File tree

msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ public MessagePacker(MessageBufferOutput out, MessagePack.Config config) {
8686
/**
8787
* Reset output. This method doesn't close the old resource.
8888
* @param out new output
89+
* @return the old resource
8990
*/
90-
public void reset(MessageBufferOutput out) throws IOException {
91+
public MessageBufferOutput reset(MessageBufferOutput out) throws IOException {
9192
// Validate the argument
9293
MessageBufferOutput newOut = checkNotNull(out, "MessageBufferOutput is null");
9394

9495
// Reset the internal states
96+
MessageBufferOutput old = this.out;
9597
this.out = newOut;
9698
this.position = 0;
99+
return old;
97100
}
98101

99102

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,21 @@ public MessageUnpacker(MessageBufferInput in, MessagePack.Config config) {
149149
/**
150150
* Reset input. This method doesn't close the old resource.
151151
* @param in new input
152+
* @return the old resource
152153
*/
153-
public void reset(MessageBufferInput in) throws IOException {
154+
public MessageBufferInput reset(MessageBufferInput in) throws IOException {
154155
MessageBufferInput newIn = checkNotNull(in, "MessageBufferInput is null");
155156

156157
// Reset the internal states
158+
MessageBufferInput old = this.in;
157159
this.in = newIn;
158160
this.buffer = EMPTY_BUFFER;
159161
this.position = 0;
160162
this.totalReadBytes = 0;
161163
this.secondaryBuffer = null;
162164
this.reachedEOF = false;
163165
// No need to initialize the already allocated string decoder here since we can reuse it.
166+
return old;
164167
}
165168

166169
public long getTotalReadBytes() {

msgpack-core/src/main/java/org/msgpack/core/buffer/ArrayBufferInput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public ArrayBufferInput(byte[] arr, int offset, int length) {
2727
/**
2828
* Reset buffer. This method doesn't close the old resource.
2929
* @param buf new buffer
30+
* @return the old resource
3031
*/
31-
public void reset(MessageBuffer buf) {
32+
public MessageBuffer reset(MessageBuffer buf) {
33+
MessageBuffer old = this.buffer;
3234
this.buffer = buf;
3335
this.isRead = false;
36+
return old;
3437
}
3538

3639
public void reset(byte[] arr) {

msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public ByteBufferInput(ByteBuffer input) {
1919
/**
2020
* Reset buffer. This method doesn't close the old resource.
2121
* @param input new buffer
22+
* @return the old resource
2223
*/
23-
public void reset(ByteBuffer input) {
24+
public ByteBuffer reset(ByteBuffer input) {
25+
ByteBuffer old = this.input;
2426
this.input = input;
2527
isRead = false;
28+
return old;
2629
}
2730

2831
@Override

msgpack-core/src/main/java/org/msgpack/core/buffer/ChannelBufferInput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public ChannelBufferInput(ReadableByteChannel channel, int bufferSize) {
2828
/**
2929
* Reset channel. This method doesn't close the old resource.
3030
* @param channel new channel
31+
* @return the old resource
3132
*/
32-
public void reset(ReadableByteChannel channel) throws IOException {
33+
public ReadableByteChannel reset(ReadableByteChannel channel) throws IOException {
34+
ReadableByteChannel old = this.channel;
3335
this.channel = channel;
3436
this.reachedEOF = false;
37+
return old;
3538
}
3639

3740
@Override

msgpack-core/src/main/java/org/msgpack/core/buffer/ChannelBufferOutput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public ChannelBufferOutput(WritableByteChannel channel) {
2121
/**
2222
* Reset channel. This method doesn't close the old resource.
2323
* @param channel new channel
24+
* @return the old resource
2425
*/
25-
public void reset(WritableByteChannel channel) throws IOException {
26+
public WritableByteChannel reset(WritableByteChannel channel) throws IOException {
27+
WritableByteChannel old = this.channel;
2628
this.channel = channel;
29+
return old;
2730
}
2831

2932

msgpack-core/src/main/java/org/msgpack/core/buffer/InputStreamBufferInput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ public InputStreamBufferInput(InputStream in, int bufferSize) {
3535
/**
3636
* Reset Stream. This method doesn't close the old resource.
3737
* @param in new stream
38+
* @return the old resource
3839
*/
39-
public void reset(InputStream in) throws IOException {
40+
public InputStream reset(InputStream in) throws IOException {
41+
InputStream old = this.in;
4042
this.in = in;
4143
reachedEOF = false;
44+
return old;
4245
}
4346

4447

msgpack-core/src/main/java/org/msgpack/core/buffer/OutputStreamBufferOutput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public OutputStreamBufferOutput(OutputStream out) {
2121
/**
2222
* Reset Stream. This method doesn't close the old resource.
2323
* @param out new stream
24+
* @return the old resource
2425
*/
25-
public void reset(OutputStream out) throws IOException {
26+
public OutputStream reset(OutputStream out) throws IOException {
27+
OutputStream old = this.out;
2628
this.out = out;
29+
return old;
2730
}
2831

2932
@Override

0 commit comments

Comments
 (0)