Skip to content

Commit 75763c7

Browse files
committed
Packer implements Flushable
1 parent 1a65c33 commit 75763c7

10 files changed

Lines changed: 72 additions & 7 deletions

File tree

src/main/java/org/msgpack/io/BufferedOutput.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private void reserve(int len) throws IOException {
5353
}
5454
}
5555

56+
@Override
5657
public void write(byte[] b, int off, int len) throws IOException {
5758
if(buffer == null) {
5859
if(bufferSize < len) {
@@ -77,6 +78,7 @@ public void write(byte[] b, int off, int len) throws IOException {
7778
}
7879
}
7980

81+
@Override
8082
public void write(ByteBuffer bb) throws IOException {
8183
int len = bb.remaining();
8284
if(buffer == null) {
@@ -102,82 +104,95 @@ public void write(ByteBuffer bb) throws IOException {
102104
}
103105
}
104106

107+
@Override
105108
public void writeByte(byte v) throws IOException {
106109
reserve(1);
107110
buffer[filled++] = v;
108111
}
109112

113+
@Override
110114
public void writeShort(short v) throws IOException {
111115
reserve(2);
112116
castByteBuffer.putShort(filled, v);
113117
filled += 2;
114118
}
115119

120+
@Override
116121
public void writeInt(int v) throws IOException {
117122
reserve(4);
118123
castByteBuffer.putInt(filled, v);
119124
filled += 4;
120125
}
121126

127+
@Override
122128
public void writeLong(long v) throws IOException {
123129
reserve(8);
124130
castByteBuffer.putLong(filled, v);
125131
filled += 8;
126132
}
127133

134+
@Override
128135
public void writeFloat(float v) throws IOException {
129136
reserve(4);
130137
castByteBuffer.putFloat(filled, v);
131138
filled += 4;
132139
}
133140

141+
@Override
134142
public void writeDouble(double v) throws IOException {
135143
reserve(8);
136144
castByteBuffer.putDouble(filled, v);
137145
filled += 8;
138146
}
139147

148+
@Override
140149
public void writeByteAndByte(byte b, byte v) throws IOException {
141150
reserve(2);
142151
buffer[filled++] = b;
143152
buffer[filled++] = v;
144153
}
145154

155+
@Override
146156
public void writeByteAndShort(byte b, short v) throws IOException {
147157
reserve(3);
148158
buffer[filled++] = b;
149159
castByteBuffer.putShort(filled, v);
150160
filled += 2;
151161
}
152162

163+
@Override
153164
public void writeByteAndInt(byte b, int v) throws IOException {
154165
reserve(5);
155166
buffer[filled++] = b;
156167
castByteBuffer.putInt(filled, v);
157168
filled += 4;
158169
}
159170

171+
@Override
160172
public void writeByteAndLong(byte b, long v) throws IOException {
161173
reserve(9);
162174
buffer[filled++] = b;
163175
castByteBuffer.putLong(filled, v);
164176
filled += 8;
165177
}
166178

179+
@Override
167180
public void writeByteAndFloat(byte b, float v) throws IOException {
168181
reserve(5);
169182
buffer[filled++] = b;
170183
castByteBuffer.putFloat(filled, v);
171184
filled += 4;
172185
}
173186

187+
@Override
174188
public void writeByteAndDouble(byte b, double v) throws IOException {
175189
reserve(9);
176190
buffer[filled++] = b;
177191
castByteBuffer.putDouble(filled, v);
178192
filled += 8;
179193
}
180194

195+
@Override
181196
public void flush() throws IOException {
182197
if(filled > 0) {
183198
if(!flushBuffer(buffer, 0, filled)) {

src/main/java/org/msgpack/io/ByteBufferOutput.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,85 +48,101 @@ private void reserve(int len) throws IOException {
4848
buffer = callback.call(buffer, len);
4949
}
5050

51+
@Override
5152
public void write(byte[] b, int off, int len) throws IOException {
5253
reserve(len);
5354
buffer.put(b, off, len);
5455
}
5556

57+
@Override
5658
public void write(ByteBuffer bb) throws IOException {
5759
reserve(bb.remaining());
5860
buffer.put(bb);
5961
}
6062

63+
@Override
6164
public void writeByte(byte v) throws IOException {
6265
reserve(1);
6366
buffer.put(v);
6467
}
6568

69+
@Override
6670
public void writeShort(short v) throws IOException {
6771
reserve(2);
6872
buffer.putShort(v);
6973
}
7074

75+
@Override
7176
public void writeInt(int v) throws IOException {
7277
reserve(4);
7378
buffer.putInt(v);
7479
}
7580

81+
@Override
7682
public void writeLong(long v) throws IOException {
7783
reserve(8);
7884
buffer.putLong(v);
7985
}
8086

87+
@Override
8188
public void writeFloat(float v) throws IOException {
8289
reserve(4);
8390
buffer.putFloat(v);
8491
}
8592

93+
@Override
8694
public void writeDouble(double v) throws IOException {
8795
reserve(8);
8896
buffer.putDouble(v);
8997
}
9098

99+
@Override
91100
public void writeByteAndByte(byte b, byte v) throws IOException {
92101
reserve(2);
93102
buffer.put(b);
94103
buffer.put(v);
95104
}
96105

106+
@Override
97107
public void writeByteAndShort(byte b, short v) throws IOException {
98108
reserve(3);
99109
buffer.put(b);
100110
buffer.putShort(v);
101111
}
102112

113+
@Override
103114
public void writeByteAndInt(byte b, int v) throws IOException {
104115
reserve(5);
105116
buffer.put(b);
106117
buffer.putInt(v);
107118
}
108119

120+
@Override
109121
public void writeByteAndLong(byte b, long v) throws IOException {
110122
reserve(9);
111123
buffer.put(b);
112124
buffer.putLong(v);
113125
}
114126

127+
@Override
115128
public void writeByteAndFloat(byte b, float v) throws IOException {
116129
reserve(5);
117130
buffer.put(b);
118131
buffer.putFloat(v);
119132
}
120133

134+
@Override
121135
public void writeByteAndDouble(byte b, double v) throws IOException {
122136
reserve(9);
123137
buffer.put(b);
124138
buffer.putDouble(v);
125139
}
126140

141+
@Override
127142
public void flush() throws IOException {
128143
}
129144

145+
@Override
130146
public void close() {
131147
}
132148
}

src/main/java/org/msgpack/io/LinkedBufferOutput.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public int getSize() {
5858
return size + filled;
5959
}
6060

61+
@Override
6162
protected boolean flushBuffer(byte[] b, int off, int len) {
6263
link.add(new Link(b, off, len));
6364
size += len;
@@ -70,6 +71,7 @@ public void clear() {
7071
filled = 0;
7172
}
7273

74+
@Override
7375
public void close() {
7476
}
7577
}

src/main/java/org/msgpack/io/Output.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
import java.io.IOException;
2121
import java.io.Closeable;
22+
import java.io.Flushable;
2223
import java.nio.ByteBuffer;
2324

2425

25-
public interface Output extends Closeable {
26+
public interface Output extends Closeable, Flushable {
2627
public void write(byte[] b, int off, int len) throws IOException;
2728

2829
public void write(ByteBuffer bb) throws IOException;

src/main/java/org/msgpack/io/StreamOutput.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public StreamOutput(OutputStream out) {
2929
this.out = new DataOutputStream(out);
3030
}
3131

32+
@Override
3233
public void write(byte[] b, int off, int len) throws IOException {
3334
out.write(b, off, len);
3435
}
3536

37+
@Override
3638
public void write(ByteBuffer bb) throws IOException {
3739
if(bb.hasArray()) {
3840
byte[] array = bb.array();
@@ -47,63 +49,77 @@ public void write(ByteBuffer bb) throws IOException {
4749
}
4850
}
4951

52+
@Override
5053
public void writeByte(byte v) throws IOException {
5154
out.write(v);
5255
}
5356

57+
@Override
5458
public void writeShort(short v) throws IOException {
5559
out.writeShort(v);
5660
}
5761

62+
@Override
5863
public void writeInt(int v) throws IOException {
5964
out.writeInt(v);
6065
}
6166

67+
@Override
6268
public void writeLong(long v) throws IOException {
6369
out.writeLong(v);
6470
}
6571

72+
@Override
6673
public void writeFloat(float v) throws IOException {
6774
out.writeFloat(v);
6875
}
6976

77+
@Override
7078
public void writeDouble(double v) throws IOException {
7179
out.writeDouble(v);
7280
}
7381

82+
@Override
7483
public void writeByteAndByte(byte b, byte v) throws IOException {
7584
out.write(b);
7685
out.write(v);
7786
}
7887

88+
@Override
7989
public void writeByteAndShort(byte b, short v) throws IOException {
8090
out.write(b);
8191
out.writeShort(v);
8292
}
8393

94+
@Override
8495
public void writeByteAndInt(byte b, int v) throws IOException {
8596
out.write(b);
8697
out.writeInt(v);
8798
}
8899

100+
@Override
89101
public void writeByteAndLong(byte b, long v) throws IOException {
90102
out.write(b);
91103
out.writeLong(v);
92104
}
93105

106+
@Override
94107
public void writeByteAndFloat(byte b, float v) throws IOException {
95108
out.write(b);
96109
out.writeFloat(v);
97110
}
98111

112+
@Override
99113
public void writeByteAndDouble(byte b, double v) throws IOException {
100114
out.write(b);
101115
out.writeDouble(v);
102116
}
103117

118+
@Override
104119
public void flush() throws IOException {
105120
}
106121

122+
@Override
107123
public void close() throws IOException {
108124
out.close();
109125
}

src/main/java/org/msgpack/packer/MessagePackPacker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ public void reset() {
324324
stack.clear();
325325
}
326326

327+
@Override
328+
public void flush() throws IOException {
329+
out.flush();
330+
}
331+
332+
@Override
327333
public void close() throws IOException {
328334
out.close();
329335
}

src/main/java/org/msgpack/packer/Packer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.math.BigInteger;
2121
import java.io.IOException;
2222
import java.io.Closeable;
23+
import java.io.Flushable;
2324
import java.nio.ByteBuffer;
2425
import org.msgpack.type.Value;
2526

@@ -30,7 +31,7 @@
3031
*
3132
* @version 0.6.0
3233
*/
33-
public interface Packer extends Closeable {
34+
public interface Packer extends Closeable, Flushable {
3435
public Packer write(boolean o) throws IOException;
3536

3637
public Packer write(byte o) throws IOException;

src/main/java/org/msgpack/packer/Unconverter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,13 @@ private void putContainer(Value v) {
215215
stack.reduceCount();
216216
}
217217
}
218+
219+
@Override
220+
public void flush() throws IOException {
221+
}
222+
223+
@Override
224+
public void close() throws IOException {
225+
}
218226
}
219227

src/main/java/org/msgpack/unpacker/AbstractUnpacker.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,5 @@ public <T> T read(T to) throws IOException {
7979
Template<? super T> tmpl = msgpack.lookup((Class<T>) to.getClass());
8080
return (T) tmpl.read(this, to);
8181
}
82-
83-
84-
@Override
85-
public void close() throws IOException {
86-
}
8782
}
8883

0 commit comments

Comments
 (0)