1
1
package com .github .plokhotnyuk .jsoniter_scala
2
2
3
3
import java .io .{InputStream , OutputStream }
4
+ import scala .{specialized => sp }
4
5
5
6
package object core {
6
7
private [this ] final val readerConfig = new ReaderConfig
@@ -29,7 +30,7 @@ package object core {
29
30
* while some input bytes are expected
30
31
* @throws NullPointerException if the `codec` or `in` is null
31
32
*/
32
- final def read [A ](in : InputStream )(implicit codec : JsonValueCodec [A ]): A = {
33
+ final def read [@ sp A ](in : InputStream )(implicit codec : JsonValueCodec [A ]): A = {
33
34
if (in eq null ) throw new NullPointerException
34
35
readerPool.get.read(codec, in, readerConfig)
35
36
}
@@ -48,7 +49,7 @@ package object core {
48
49
* while some input bytes are expected
49
50
* @throws NullPointerException if the `codec`, `in` or `config` is null
50
51
*/
51
- final def read [A ](in : InputStream , config : ReaderConfig )(implicit codec : JsonValueCodec [A ]): A = {
52
+ final def read [@ sp A ](in : InputStream , config : ReaderConfig )(implicit codec : JsonValueCodec [A ]): A = {
52
53
if (in eq null ) throw new NullPointerException
53
54
readerPool.get.read(codec, in, config)
54
55
}
@@ -71,8 +72,8 @@ package object core {
71
72
* @throws NullPointerException if the `codec`, `in` or `config` is null
72
73
* @throws Throwable if some error was thrown by f() call
73
74
*/
74
- final def scanValueStream [A ](in : InputStream , config : ReaderConfig = readerConfig)(f : A => Boolean )
75
- (implicit codec : JsonValueCodec [A ]): Unit = {
75
+ final def scanValueStream [@ sp A ](in : InputStream , config : ReaderConfig = readerConfig)(f : A => Boolean )
76
+ (implicit codec : JsonValueCodec [A ]): Unit = {
76
77
if ((in eq null ) || (f eq null )) throw new NullPointerException
77
78
readerPool.get.scanValueStream(codec, in, config)(f)
78
79
}
@@ -95,8 +96,8 @@ package object core {
95
96
* @throws NullPointerException if the `codec`, `in` or `config` is null
96
97
* @throws Throwable if some error was thrown by f() call
97
98
*/
98
- final def scanArray [A ](in : InputStream , config : ReaderConfig = readerConfig)(f : A => Boolean )
99
- (implicit codec : JsonValueCodec [A ]): Unit = {
99
+ final def scanArray [@ sp A ](in : InputStream , config : ReaderConfig = readerConfig)(f : A => Boolean )
100
+ (implicit codec : JsonValueCodec [A ]): Unit = {
100
101
if ((in eq null ) || (f eq null )) throw new NullPointerException
101
102
readerPool.get.scanArray(codec, in, config)(f)
102
103
}
@@ -117,7 +118,7 @@ package object core {
117
118
* also in case if end of input is detected while some input bytes are expected
118
119
* @throws NullPointerException If the `codec` or `buf` is null.
119
120
*/
120
- final def read [A ](buf : Array [Byte ])(implicit codec : JsonValueCodec [A ]): A =
121
+ final def read [@ sp A ](buf : Array [Byte ])(implicit codec : JsonValueCodec [A ]): A =
121
122
readerPool.get.read(codec, buf, 0 , buf.length, readerConfig)
122
123
123
124
/**
@@ -134,7 +135,7 @@ package object core {
134
135
* also in case if end of input is detected while some input bytes are expected
135
136
* @throws NullPointerException if the `codec`, `buf` or `config` is null
136
137
*/
137
- final def read [A ](buf : Array [Byte ], config : ReaderConfig )(implicit codec : JsonValueCodec [A ]): A =
138
+ final def read [@ sp A ](buf : Array [Byte ], config : ReaderConfig )(implicit codec : JsonValueCodec [A ]): A =
138
139
readerPool.get.read(codec, buf, 0 , buf.length, config)
139
140
140
141
/**
@@ -155,8 +156,8 @@ package object core {
155
156
* @throws ArrayIndexOutOfBoundsException if the `to` is greater than `buf` length or negative,
156
157
* or `from` is greater than `to` or negative
157
158
*/
158
- final def read [A ](buf : Array [Byte ], from : Int , to : Int , config : ReaderConfig = readerConfig)
159
- (implicit codec : JsonValueCodec [A ]): A = {
159
+ final def read [@ sp A ](buf : Array [Byte ], from : Int , to : Int , config : ReaderConfig = readerConfig)
160
+ (implicit codec : JsonValueCodec [A ]): A = {
160
161
if (to > buf.length || to < 0 )
161
162
throw new ArrayIndexOutOfBoundsException (" `to` should be positive and not greater than `buf` length" )
162
163
if (from > to || from < 0 )
@@ -174,7 +175,7 @@ package object core {
174
175
* @param codec a codec for the given value
175
176
* @throws NullPointerException if the `codec` or `config` is null
176
177
*/
177
- final def write [A ](x : A , out : OutputStream )(implicit codec : JsonValueCodec [A ]): Unit = {
178
+ final def write [@ sp A ](x : A , out : OutputStream )(implicit codec : JsonValueCodec [A ]): Unit = {
178
179
if (out eq null ) throw new NullPointerException
179
180
writerPool.get.write(codec, x, out, writerConfig)
180
181
}
@@ -190,7 +191,7 @@ package object core {
190
191
* @param codec a codec for the given value
191
192
* @throws NullPointerException if the `codec`, `out` or `config` is null
192
193
*/
193
- final def write [A ](x : A , out : OutputStream , config : WriterConfig )(implicit codec : JsonValueCodec [A ]): Unit = {
194
+ final def write [@ sp A ](x : A , out : OutputStream , config : WriterConfig )(implicit codec : JsonValueCodec [A ]): Unit = {
194
195
if (out eq null ) throw new NullPointerException
195
196
writerPool.get.write(codec, x, out, config)
196
197
}
@@ -205,7 +206,8 @@ package object core {
205
206
* @return a byte array with `x` serialized to JSON
206
207
* @throws NullPointerException if the `codec` is null
207
208
*/
208
- final def write [A ](x : A )(implicit codec : JsonValueCodec [A ]): Array [Byte ] = writerPool.get.write(codec, x, writerConfig)
209
+ final def write [@ sp A ](x : A )(implicit codec : JsonValueCodec [A ]): Array [Byte ] =
210
+ writerPool.get.write(codec, x, writerConfig)
209
211
210
212
/**
211
213
* Serialize the `x` argument to a new allocated instance of byte array in UTF-8 encoding of JSON format,
@@ -218,7 +220,7 @@ package object core {
218
220
* @return a byte array with `x` serialized to JSON
219
221
* @throws NullPointerException if the `codec` or `config` is null
220
222
*/
221
- final def write [A ](x : A , config : WriterConfig )(implicit codec : JsonValueCodec [A ]): Array [Byte ] =
223
+ final def write [@ sp A ](x : A , config : WriterConfig )(implicit codec : JsonValueCodec [A ]): Array [Byte ] =
222
224
writerPool.get.write(codec, x, config)
223
225
224
226
/**
@@ -236,8 +238,8 @@ package object core {
236
238
* @throws ArrayIndexOutOfBoundsException if the `from` is greater than `buf` length or negative,
237
239
* or `buf` length was exceeded during serialization
238
240
*/
239
- final def write [A ](x : A , buf : Array [Byte ], from : Int , config : WriterConfig = writerConfig)
240
- (implicit codec : JsonValueCodec [A ]): Int = {
241
+ final def write [@ sp A ](x : A , buf : Array [Byte ], from : Int , config : WriterConfig = writerConfig)
242
+ (implicit codec : JsonValueCodec [A ]): Int = {
241
243
if (from > buf.length || from < 0 ) // also checks that `buf` is not null before any serialization
242
244
throw new ArrayIndexOutOfBoundsException (" `from` should be positive and not greater than `buf` length" )
243
245
writerPool.get.write(codec, x, buf, from, config)
0 commit comments