Skip to content

Commit 8dadf29

Browse files
committed
Minor refactoring... and more javadoc stuff
1 parent 2493625 commit 8dadf29

File tree

3 files changed

+66
-30
lines changed

3 files changed

+66
-30
lines changed

src/main/java/com/fasterxml/jackson/core/io/IOContext.java

+48-16
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ public void setEncoding(JsonEncoding enc) {
109109
_encoding = enc;
110110
}
111111

112-
/**
113-
* @since 1.6
114-
*/
115112
public IOContext withEncoding(JsonEncoding enc) {
116113
_encoding = enc;
117114
return this;
@@ -138,29 +135,54 @@ public TextBuffer constructTextBuffer() {
138135
}
139136

140137
/**
138+
* Method for recycling or allocation byte buffer of "read I/O" type.
141139
*<p>
142140
* Note: the method can only be called once during its life cycle.
143141
* This is to protect against accidental sharing.
142+
*
143+
* @return Allocated or recycled byte buffer
144144
*/
145145
public byte[] allocReadIOBuffer() {
146146
_verifyAlloc(_readIOBuffer);
147147
return (_readIOBuffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER));
148148
}
149149

150150
/**
151+
* Variant of {@link #allocReadIOBuffer()} that specifies smallest acceptable
152+
* buffer size.
153+
*
154+
* @param minSize Minimum size of the buffer to recycle or allocate
155+
*
156+
* @return Allocated or recycled byte buffer
157+
*
151158
* @since 2.4
152159
*/
153160
public byte[] allocReadIOBuffer(int minSize) {
154161
_verifyAlloc(_readIOBuffer);
155162
return (_readIOBuffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER, minSize));
156163
}
157-
164+
165+
/**
166+
* Method for recycling or allocation byte buffer of "write encoding" type.
167+
*<p>
168+
* Note: the method can only be called once during its life cycle.
169+
* This is to protect against accidental sharing.
170+
*
171+
* @return Allocated or recycled byte buffer
172+
*/
158173
public byte[] allocWriteEncodingBuffer() {
159174
_verifyAlloc(_writeEncodingBuffer);
160175
return (_writeEncodingBuffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_WRITE_ENCODING_BUFFER));
161176
}
162177

163178
/**
179+
* Variant of {@link #allocWriteEncodingBuffer()} that specifies smallest acceptable
180+
* buffer size.
181+
*
182+
* @param minSize Minimum size of the buffer to recycle or allocate
183+
*
184+
* @return Allocated or recycled byte buffer
185+
*
164186
* @since 2.4
165187
*/
166188
public byte[] allocWriteEncodingBuffer(int minSize) {
@@ -169,14 +191,26 @@ public byte[] allocWriteEncodingBuffer(int minSize) {
169191
}
170192

171193
/**
172-
* @since 2.1
194+
* Method for recycling or allocation byte buffer of "base 64 encode/decode" type.
195+
*<p>
196+
* Note: the method can only be called once during its life cycle.
197+
* This is to protect against accidental sharing.
198+
*
199+
* @return Allocated or recycled byte buffer
173200
*/
174201
public byte[] allocBase64Buffer() {
175202
_verifyAlloc(_base64Buffer);
176203
return (_base64Buffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_BASE64_CODEC_BUFFER));
177204
}
178205

179206
/**
207+
* Variant of {@link #allocBase64Buffer()} that specifies smallest acceptable
208+
* buffer size.
209+
*
210+
* @param minSize Minimum size of the buffer to recycle or allocate
211+
*
212+
* @return Allocated or recycled byte buffer
213+
*
180214
* @since 2.9
181215
*/
182216
public byte[] allocBase64Buffer(int minSize) {
@@ -189,9 +223,7 @@ public char[] allocTokenBuffer() {
189223
return (_tokenCBuffer = _bufferRecycler.allocCharBuffer(BufferRecycler.CHAR_TOKEN_BUFFER));
190224
}
191225

192-
/**
193-
* @since 2.4
194-
*/
226+
// @since 2.4
195227
public char[] allocTokenBuffer(int minSize) {
196228
_verifyAlloc(_tokenCBuffer);
197229
return (_tokenCBuffer = _bufferRecycler.allocCharBuffer(BufferRecycler.CHAR_TOKEN_BUFFER, minSize));
@@ -210,12 +242,13 @@ public char[] allocNameCopyBuffer(int minSize) {
210242
/**
211243
* Method to call when all the processing buffers can be safely
212244
* recycled.
245+
*
246+
* @param buf Buffer instance to release (return for recycling)
213247
*/
214248
public void releaseReadIOBuffer(byte[] buf) {
215249
if (buf != null) {
216-
/* Let's do sanity checks to ensure once-and-only-once release,
217-
* as well as avoiding trying to release buffers not owned
218-
*/
250+
// Let's do sanity checks to ensure once-and-only-once release,
251+
// as well as avoiding trying to release buffers not owned
219252
_verifyRelease(buf, _readIOBuffer);
220253
_readIOBuffer = null;
221254
_bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER, buf);
@@ -224,9 +257,8 @@ public void releaseReadIOBuffer(byte[] buf) {
224257

225258
public void releaseWriteEncodingBuffer(byte[] buf) {
226259
if (buf != null) {
227-
/* Let's do sanity checks to ensure once-and-only-once release,
228-
* as well as avoiding trying to release buffers not owned
229-
*/
260+
// Let's do sanity checks to ensure once-and-only-once release,
261+
// as well as avoiding trying to release buffers not owned
230262
_verifyRelease(buf, _writeEncodingBuffer);
231263
_writeEncodingBuffer = null;
232264
_bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_WRITE_ENCODING_BUFFER, buf);
@@ -268,9 +300,9 @@ public void releaseNameCopyBuffer(char[] buf) {
268300
}
269301

270302
/*
271-
/**********************************************************
303+
/**********************************************************************
272304
/* Internal helpers
273-
/**********************************************************
305+
/**********************************************************************
274306
*/
275307

276308
protected final void _verifyAlloc(Object buffer) {

src/main/java/com/fasterxml/jackson/core/io/JsonEOFException.java

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public JsonEOFException(JsonParser p, JsonToken token, String msg) {
3030
/**
3131
* Accessor for possibly available information about token that was being
3232
* decoded while encountering end of input.
33+
*
34+
* @return JsonToken that was being decoded while encountering end-of-input
3335
*/
3436
public JsonToken getTokenBeingDecoded() {
3537
return _token;

src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ protected VersionUtil() { }
4444
/**********************************************************************
4545
*/
4646

47-
/**
48-
* Alias of {@link #packageVersionFor(Class)}.
49-
*
50-
* @param cls Class for which to look version information
51-
*
52-
* @return Version information discovered if any;
53-
* {@link Version#unknownVersion()} if none
54-
*/
55-
public static Version versionFor(Class<?> cls)
56-
{
57-
return packageVersionFor(cls);
58-
}
59-
6047
/**
6148
* Loads version information by introspecting a class named
6249
* "PackageVersion" in the same package as the given class.
@@ -70,7 +57,7 @@ public static Version versionFor(Class<?> cls)
7057
* @return Version information discovered if any;
7158
* {@link Version#unknownVersion()} if none
7259
*/
73-
public static Version packageVersionFor(Class<?> cls)
60+
public static Version versionFor(Class<?> cls)
7461
{
7562
Version v = null;
7663
try {
@@ -88,6 +75,21 @@ public static Version packageVersionFor(Class<?> cls)
8875
return (v == null) ? Version.unknownVersion() : v;
8976
}
9077

78+
/**
79+
* Alias of {@link #versionFor(Class)}.
80+
*
81+
* @param cls Class for which to look version information
82+
*
83+
* @return Version information discovered if any;
84+
* {@link Version#unknownVersion()} if none
85+
*
86+
* @deprecated Since 2.12 simply use {@link #versionFor(Class)} instead
87+
*/
88+
@Deprecated
89+
public static Version packageVersionFor(Class<?> cls) {
90+
return versionFor(cls);
91+
}
92+
9193
/**
9294
* Will attempt to load the maven version for the given groupId and
9395
* artifactId. Maven puts a pom.properties file in

0 commit comments

Comments
 (0)