|
1 | 1 | package com.jsoniter.output; |
2 | 2 |
|
3 | | -import java.io.ByteArrayOutputStream; |
4 | | - |
5 | 3 | public class JsonStreamPool { |
6 | 4 |
|
7 | 5 | private final static ThreadLocal<JsonStream> slot1 = new ThreadLocal<JsonStream>(); |
8 | 6 | private final static ThreadLocal<JsonStream> slot2 = new ThreadLocal<JsonStream>(); |
9 | | - private final static ThreadLocal<AsciiOutputStream> osSlot1 = new ThreadLocal<AsciiOutputStream>(); |
10 | | - private final static ThreadLocal<AsciiOutputStream> osSlot2 = new ThreadLocal<AsciiOutputStream>(); |
11 | | - private final static ThreadLocal<ByteArrayOutputStream> baosSlot1 = new ThreadLocal<ByteArrayOutputStream>(); |
12 | | - private final static ThreadLocal<ByteArrayOutputStream> baosSlot2 = new ThreadLocal<ByteArrayOutputStream>(); |
13 | 7 |
|
14 | 8 | public static JsonStream borrowJsonStream() { |
15 | 9 | JsonStream stream = slot1.get(); |
@@ -38,53 +32,4 @@ public static void returnJsonStream(JsonStream jsonStream) { |
38 | 32 | } |
39 | 33 | } |
40 | 34 |
|
41 | | - public static AsciiOutputStream borrowAsciiOutputStream() { |
42 | | - AsciiOutputStream stream = osSlot1.get(); |
43 | | - if (stream != null) { |
44 | | - osSlot1.set(null); |
45 | | - return stream; |
46 | | - } |
47 | | - stream = osSlot2.get(); |
48 | | - if (stream != null) { |
49 | | - osSlot2.set(null); |
50 | | - return stream; |
51 | | - } |
52 | | - return new AsciiOutputStream(); |
53 | | - } |
54 | | - |
55 | | - public static void returnAsciiOutputStream(AsciiOutputStream asciiOutputStream) { |
56 | | - if (osSlot1.get() == null) { |
57 | | - osSlot1.set(asciiOutputStream); |
58 | | - return; |
59 | | - } |
60 | | - if (osSlot2.get() == null) { |
61 | | - osSlot2.set(asciiOutputStream); |
62 | | - return; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - public static ByteArrayOutputStream borrowByteArrayOutputStream() { |
67 | | - ByteArrayOutputStream stream = baosSlot1.get(); |
68 | | - if (stream != null) { |
69 | | - osSlot1.set(null); |
70 | | - return stream; |
71 | | - } |
72 | | - stream = baosSlot2.get(); |
73 | | - if (stream != null) { |
74 | | - osSlot2.set(null); |
75 | | - return stream; |
76 | | - } |
77 | | - return new ByteArrayOutputStream(); |
78 | | - } |
79 | | - |
80 | | - public static void returnByteArrayOutputStream(ByteArrayOutputStream baos) { |
81 | | - if (baosSlot1.get() == null) { |
82 | | - baosSlot1.set(baos); |
83 | | - return; |
84 | | - } |
85 | | - if (baosSlot2.get() == null) { |
86 | | - baosSlot2.set(baos); |
87 | | - return; |
88 | | - } |
89 | | - } |
90 | 35 | } |
0 commit comments