Skip to content

Commit 7b7012f

Browse files
committed
Extract common code
1 parent 7102ecb commit 7b7012f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ public void flush()
153153
throws IOException
154154
{
155155
if (position > 0) {
156-
out.writeBuffer(position);
157-
buffer = null;
158-
totalFlushBytes += position;
159-
position = 0;
156+
flushBuffer();
160157
}
161158
out.flush();
162159
}
@@ -172,17 +169,23 @@ public void close()
172169
}
173170
}
174171

172+
private void flushBuffer()
173+
throws IOException
174+
{
175+
out.writeBuffer(position);
176+
buffer = null;
177+
totalFlushBytes += position;
178+
position = 0;
179+
}
180+
175181
private void ensureCapacity(int mimimumSize)
176182
throws IOException
177183
{
178184
if (buffer == null) {
179185
buffer = out.next(mimimumSize);
180186
}
181187
else if (position + mimimumSize >= buffer.size()) {
182-
out.writeBuffer(position);
183-
buffer = null;
184-
totalFlushBytes += position;
185-
position = 0;
188+
flushBuffer();
186189
buffer = out.next(mimimumSize);
187190
}
188191
}

0 commit comments

Comments
 (0)