File tree 3 files changed +55
-5
lines changed
3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -125,5 +125,48 @@ Expected output:
125
125
126
126
## RFC-8259 validation (example02)
127
127
128
- An example of a command line application that reads the system input, parses and validates JSON according to the latest
129
- specification and in case of any error prints it to the system error output
128
+ An example of a command line application that reads the provided file, parses and validates JSON according to the latest
129
+ specification and in case of any error prints it to the system error output.
130
+
131
+ For faster JSON validation the example uses reading through memory mapped files which are not supported by Scala.js.
132
+
133
+ ### Build uber jar, print its size, and measure its start up time
134
+
135
+ ``` sh
136
+ scala-cli --power package --assembly example02.sc --force -o example02.jar
137
+ ls -l ./example02.jar
138
+ time ./example02.jar test.json 2> /dev/null
139
+ ```
140
+ Expected output:
141
+ ``` text
142
+ real 0m0.096s
143
+ user 0m0.138s
144
+ sys 0m0.017s
145
+ ```
146
+ ### Build GraalVM native image, print its size, and measure its start up time
147
+
148
+ ``` sh
149
+ scala-cli --power package --jvm graalvm --native-image example02.sc --force -o example02_graalvm.bin
150
+ ls -l ./example02_graalvm.bin
151
+ time ./example02_graalvm.bin test.json 2> /dev/null
152
+ ```
153
+ Expected output:
154
+ ``` text
155
+ real 0m0.003s
156
+ user 0m0.000s
157
+ sys 0m0.002s
158
+ ```
159
+
160
+ ### Build Scala Native image, print its size, and measure its start up time
161
+
162
+ ``` sh
163
+ scala-cli --power package --native-version 0.4.16 --native example02.sc --force -o example02_native.bin
164
+ ls -l ./example02_native.bin
165
+ time ./example02_native.bin test.json 2> /dev/null
166
+ ```
167
+ Expected output:
168
+ ``` text
169
+ real 0m0.003s
170
+ user 0m0.000s
171
+ sys 0m0.003s
172
+ ```
Original file line number Diff line number Diff line change 1
1
//> using dep " com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core::2.28.2"
2
2
3
3
import com .github .plokhotnyuk .jsoniter_scala .core ._
4
+ import java .io .RandomAccessFile
5
+ import java .nio .channels .FileChannel
4
6
5
7
val jsonCodec : JsonValueCodec [Unit ] = new JsonValueCodec [Unit ] {
6
8
override def decodeValue (in : JsonReader , default : Unit ): Unit = decode(in, 1024 ) // Max depth is 1024
7
9
8
10
override def encodeValue (x : Unit , out : JsonWriter ): Unit = ???
9
11
10
- override def nullValue () : Unit = ()
12
+ override def nullValue : Unit = ()
11
13
12
14
private [this ] def decode (in : JsonReader , depth : Int ): Unit = {
13
15
val b = in.nextToken()
@@ -43,10 +45,14 @@ val jsonCodec: JsonValueCodec[Unit] = new JsonValueCodec[Unit] {
43
45
}) ()
44
46
if (! in.isCurrentToken('}' )) in.objectEndOrCommaError()
45
47
}
46
- } else in.readNullOrError(nullValue() , " expected JSON value" )
48
+ } else in.readNullOrError(nullValue, " expected JSON value" )
47
49
}
48
50
}
49
51
50
- try readFromStream(System .in)(jsonCodec) catch {
52
+ try {
53
+ val fileChannel = new RandomAccessFile (args(0 ), " rw" ).getChannel
54
+ val mappedByteBuffer = fileChannel.map(FileChannel .MapMode .READ_WRITE , 0 , fileChannel.size)
55
+ readFromByteBuffer(mappedByteBuffer)(jsonCodec)
56
+ } catch {
51
57
case ex : Throwable => ex.printStackTrace(System .err)
52
58
}
Original file line number Diff line number Diff line change
1
+ {"x:123 }
You can’t perform that action at this time.
0 commit comments