Skip to content

Commit f2ee139

Browse files
committed
Add factory method template for creating packer/unpacker instances
1 parent a9a6367 commit f2ee139

4 files changed

Lines changed: 75 additions & 10 deletions

File tree

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
package org.msgpack.core;
22

3+
import java.io.IOException;
4+
35
/**
4-
*
6+
* Provides a sequence of MessageBuffers that contains message packed data.
57
*/
68
public interface MessageBufferInput {
79

10+
/**
11+
* Get a next buffer to read
12+
* @return
13+
* @throws IOException
14+
*/
15+
public MessageBuffer next() throws IOException;
16+
17+
/**
18+
* Close this buffer input
19+
* @throws IOException
20+
*/
21+
public void close() throws IOException;
22+
823

924
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package org.msgpack.core;
22

3+
import java.io.IOException;
34

45
/**
5-
*
6+
* Provides a sequence of MessageBuffers for packing the input data
67
*/
78
public interface MessageBufferOutput {
89

10+
/**
11+
* Retrieves the next buffer for writing message packed data
12+
* @return
13+
* @throws IOException
14+
*/
15+
public MessageBuffer next() throws IOException;
916

17+
/**
18+
* Flush and close this buffer.
19+
* @throws IOException
20+
*/
21+
public void close() throws IOException;
1022

1123

1224
}

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package org.msgpack.core;
22

3+
import java.io.*;
4+
import java.nio.channels.ReadableByteChannel;
5+
import java.nio.channels.WritableByteChannel;
6+
import java.nio.file.Path;
7+
38
/**
4-
* Created on 2014/05/05.
9+
* Entry point for creating MessagePacker and MessageUnpacker
510
*/
611
public class MessagePack {
712

@@ -22,4 +27,44 @@ public int getLength() {
2227
}
2328
}
2429

30+
/**
31+
* Create a new MessagePacker that writes the message packed data to a file
32+
* @param outputFile
33+
* @return MessagePacker
34+
* @throws IOException if the target file cannot be created or opened
35+
*/
36+
public static MessagePacker newPacker(File outputFile) throws IOException {
37+
return newPacker(new FileOutputStream(outputFile));
38+
}
39+
40+
public static MessagePacker newPacker(OutputStream out) {
41+
// TODO
42+
return null;
43+
}
44+
45+
public static MessagePacker newPacker(WritableByteChannel out) {
46+
// TODO
47+
return null;
48+
}
49+
50+
/**
51+
* Create a new MessageUnpacker that decodes the message packed data in a file
52+
* @param inputFile
53+
* @return MessageUnpacker
54+
* @throws IOException if the input file is not found
55+
*/
56+
public static MessageUnpacker newUnpacker(File inputFile) throws IOException {
57+
return newUnpacker(new FileInputStream(inputFile));
58+
}
59+
60+
public static MessageUnpacker newUnpacker(InputStream in) {
61+
// TODO
62+
return null;
63+
}
64+
65+
public static MessageUnpacker newUnpacker(ReadableByteChannel in) {
66+
// TODO
67+
return null;
68+
}
69+
2570
}

msgpack-core/src/test/scala/org/msgpack/core/MessageBufferTest.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ import java.nio.ByteBuffer
44
import xerial.core.log.LogLevel
55
import scala.util.Random
66

7-
object Test {
8-
val b = ByteBuffer.allocate(10)
9-
b.getInt(0)
10-
11-
val m = MessageBuffer.newBuffer(10)
12-
m.getInt(0)
13-
}
147

158
/**
169
* Created on 2014/05/01.

0 commit comments

Comments
 (0)