Skip to content

Commit b8e51a6

Browse files
committed
Merge v07-universal-buffer and use MessageBufferU for Android (DalvikVM)
2 parents cc2ea00 + 30d7499 commit b8e51a6

17 files changed

+483
-130
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jdk:
1010

1111
branches:
1212
only:
13-
- v07
14-
- v07-develop
13+
- /^v07.*$/
1514

1615
script: sbt ++$TRAVIS_SCALA_VERSION test
1716

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ MessagePack for Java
77

88
MessagePack v7 (0.7.x) is a faster implementation of the previous version [v06](https://github.com/msgpack/msgpack-java/tree/v06), and supports all of the message pack types, including [extended format](https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext).
99

10+
## Limitation
11+
- Android and Java6 platform support is not yet ready. You can see the ongoing work here: https://github.com/msgpack/msgpack-java/tree/v07-android
12+
- Value API is in a designing phase: https://github.com/msgpack/msgpack-java/pull/109
13+
1014
## Quick Start
1115

1216
For Maven users:

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ public MessagePacker(MessageBufferOutput out, MessagePack.Config config) {
8383
this.position = 0;
8484
}
8585

86-
public void reset(MessageBufferOutput out) throws IOException {
86+
/**
87+
* Reset output. This method doesn't close the old resource.
88+
* @param out new output
89+
* @return the old resource
90+
*/
91+
public MessageBufferOutput reset(MessageBufferOutput out) throws IOException {
8792
// Validate the argument
8893
MessageBufferOutput newOut = checkNotNull(out, "MessageBufferOutput is null");
8994

90-
try {
91-
if(this.out != newOut) {
92-
this.out.close();
93-
}
94-
}
95-
finally {
96-
// Reset the internal states here for the exception safety
97-
this.out = newOut;
98-
this.position = 0;
99-
}
95+
// Reset the internal states
96+
MessageBufferOutput old = this.out;
97+
this.out = newOut;
98+
this.position = 0;
99+
return old;
100100
}
101101

102102

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,24 @@ public MessageUnpacker(MessageBufferInput in, MessagePack.Config config) {
146146
this.config = checkNotNull(config, "Config");
147147
}
148148

149-
public void reset(MessageBufferInput in) throws IOException {
149+
/**
150+
* Reset input. This method doesn't close the old resource.
151+
* @param in new input
152+
* @return the old resource
153+
*/
154+
public MessageBufferInput reset(MessageBufferInput in) throws IOException {
150155
MessageBufferInput newIn = checkNotNull(in, "MessageBufferInput is null");
151156

152-
try {
153-
if(in != newIn) {
154-
close();
155-
}
156-
}
157-
finally {
158-
// Reset the internal states here for the exception safety
159-
this.in = newIn;
160-
this.buffer = EMPTY_BUFFER;
161-
this.position = 0;
162-
this.totalReadBytes = 0;
163-
this.secondaryBuffer = null;
164-
this.reachedEOF = false;
165-
// No need to initialize the already allocated string decoder here since we can reuse it.
166-
}
157+
// Reset the internal states
158+
MessageBufferInput old = this.in;
159+
this.in = newIn;
160+
this.buffer = EMPTY_BUFFER;
161+
this.position = 0;
162+
this.totalReadBytes = 0;
163+
this.secondaryBuffer = null;
164+
this.reachedEOF = false;
165+
// No need to initialize the already allocated string decoder here since we can reuse it.
166+
return old;
167167
}
168168

169169
public long getTotalReadBytes() {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ public ArrayBufferInput(byte[] arr, int offset, int length) {
2424
this.buffer = MessageBuffer.wrap(checkNotNull(arr, "input array is null")).slice(offset, length);
2525
}
2626

27-
public void reset(MessageBuffer buf) {
27+
/**
28+
* Reset buffer. This method doesn't close the old resource.
29+
* @param buf new buffer
30+
* @return the old resource
31+
*/
32+
public MessageBuffer reset(MessageBuffer buf) {
33+
MessageBuffer old = this.buffer;
2834
this.buffer = buf;
2935
this.isRead = false;
36+
return old;
3037
}
3138

3239
public void reset(byte[] arr) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ public ByteBufferInput(ByteBuffer input) {
1616
this.input = checkNotNull(input, "input ByteBuffer is null");
1717
}
1818

19-
public void reset(ByteBuffer input) {
19+
/**
20+
* Reset buffer. This method doesn't close the old resource.
21+
* @param input new buffer
22+
* @return the old resource
23+
*/
24+
public ByteBuffer reset(ByteBuffer input) {
25+
ByteBuffer old = this.input;
2026
this.input = input;
2127
isRead = false;
28+
return old;
2229
}
2330

2431
@Override

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ public ChannelBufferInput(ReadableByteChannel channel, int bufferSize) {
2525
this.bufferSize = bufferSize;
2626
}
2727

28-
public void reset(ReadableByteChannel channel) throws IOException {
29-
this.channel.close();
28+
/**
29+
* Reset channel. This method doesn't close the old resource.
30+
* @param channel new channel
31+
* @return the old resource
32+
*/
33+
public ReadableByteChannel reset(ReadableByteChannel channel) throws IOException {
34+
ReadableByteChannel old = this.channel;
3035
this.channel = channel;
3136
this.reachedEOF = false;
37+
return old;
3238
}
39+
3340
@Override
3441
public MessageBuffer next() throws IOException {
3542

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ public ChannelBufferOutput(WritableByteChannel channel) {
1818
this.channel = checkNotNull(channel, "output channel is null");
1919
}
2020

21-
public void reset(WritableByteChannel channel) throws IOException {
22-
this.channel.close();
21+
/**
22+
* Reset channel. This method doesn't close the old resource.
23+
* @param channel new channel
24+
* @return the old resource
25+
*/
26+
public WritableByteChannel reset(WritableByteChannel channel) throws IOException {
27+
WritableByteChannel old = this.channel;
2328
this.channel = channel;
29+
return old;
2430
}
2531

2632

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ public InputStreamBufferInput(InputStream in, int bufferSize) {
3232
this.bufferSize = bufferSize;
3333
}
3434

35-
public void reset(InputStream in) throws IOException {
36-
this.in.close();
35+
/**
36+
* Reset Stream. This method doesn't close the old resource.
37+
* @param in new stream
38+
* @return the old resource
39+
*/
40+
public InputStream reset(InputStream in) throws IOException {
41+
InputStream old = this.in;
3742
this.in = in;
3843
reachedEOF = false;
44+
return old;
3945
}
4046

4147

0 commit comments

Comments
 (0)