Skip to content

Commit 5594c33

Browse files
authored
Merge pull request #396 from msgpack/javadoc-1
Adding JavaDoc
2 parents 591b480 + 49ed7ab commit 5594c33

34 files changed

+1031
-192
lines changed

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import java.util.List;
2424

2525
/**
26-
* MessagePacker that is useful to produce byte array output
26+
* MessagePacker that is useful to produce byte array output.
27+
* <p>
28+
* This class allocates a new buffer instead of resizing the buffer when data doesn't fit in the initial capacity.
29+
* This is faster than ByteArrayOutputStream especially when size of written bytes is large because resizing a buffer
30+
* usually needs to copy contents of the buffer.
2731
*/
2832
public class MessageBufferPacker
2933
extends MessagePacker
@@ -52,42 +56,69 @@ private ArrayBufferOutput getArrayBufferOut()
5256
return (ArrayBufferOutput) out;
5357
}
5458

59+
/**
60+
* Clears the written data.
61+
*/
5562
public void clear()
5663
{
5764
getArrayBufferOut().clear();
5865
}
5966

67+
/**
68+
* Gets copy of the written data as a byte array.
69+
* <p>
70+
* If your application needs better performance and smaller memory consumption, you may prefer
71+
* {@link #toMessageBuffer()} or {@link #toBufferList()} to avoid copying.
72+
*
73+
* @return the byte array
74+
*/
6075
public byte[] toByteArray()
6176
{
6277
try {
6378
flush();
6479
}
6580
catch (IOException ex) {
66-
// IOException must not happen because underlaying ArrayBufferOutput never throws IOException
81+
// IOException must not happen because underlying ArrayBufferOutput never throws IOException
6782
throw new RuntimeException(ex);
6883
}
6984
return getArrayBufferOut().toByteArray();
7085
}
7186

87+
/**
88+
* Gets the written data as a MessageBuffer.
89+
* <p>
90+
* Unlike {@link #toByteArray()}, this method omits copy of the contents if size of the written data is smaller
91+
* than a single buffer capacity.
92+
*
93+
* @return the MessageBuffer instance
94+
*/
7295
public MessageBuffer toMessageBuffer()
7396
{
7497
try {
7598
flush();
7699
}
77100
catch (IOException ex) {
78-
// IOException must not happen because underlaying ArrayBufferOutput never throws IOException
101+
// IOException must not happen because underlying ArrayBufferOutput never throws IOException
79102
throw new RuntimeException(ex);
80103
}
81104
return getArrayBufferOut().toMessageBuffer();
82105
}
83106

107+
/**
108+
* Returns the written data as a list of MessageBuffer.
109+
* <p>
110+
* Unlike {@link #toByteArray()} or {@link #toMessageBuffer()}, this is the fastest method that doesn't
111+
* copy contents in any cases.
112+
*
113+
* @return the list of MessageBuffer instances
114+
*/
84115
public List<MessageBuffer> toBufferList()
85116
{
86117
try {
87118
flush();
88119
}
89120
catch (IOException ex) {
90-
// IOException must not happen because underlaying ArrayBufferOutput never throws IOException
121+
// IOException must not happen because underlying ArrayBufferOutput never throws IOException
91122
throw new RuntimeException(ex);
92123
}
93124
return getArrayBufferOut().toBufferList();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
//
1616
package org.msgpack.core;
1717

18+
/**
19+
* Exception that indicates end of input.
20+
*/
1821
public class MessageInsufficientBufferException
1922
extends MessagePackException
2023
{

0 commit comments

Comments
 (0)