annotate Implab/Formats/Json/JsonTextScanner.cs @ 239:eedf4d834e67 v2

fix
author cin
date Wed, 13 Dec 2017 19:54:45 +0300
parents 3e26338eb977
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
1 using System;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
2 using System.Collections.Generic;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
3 using System.IO;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
4 using System.Linq;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
5 using System.Text;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
6 using System.Threading.Tasks;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
7
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
8 namespace Implab.Formats.Json {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
9 public class JsonTextScanner : JsonScanner {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
10 const int _bufferSize = 16*4096;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
11 readonly TextReader m_reader;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
12
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
13 JsonTextScanner(TextReader reader, char[] buffer) : base(buffer, 0, 0) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
14 m_reader = reader;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
15 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
16
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
17 protected override int Read(char[] buffer, int offset, int size) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
18 return m_reader.Read(buffer, offset, size);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
19 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
20
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
21 public static JsonTextScanner Create(string file, Encoding encoding) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
22 return new JsonTextScanner(new StreamReader(file, encoding), new char[_bufferSize]);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
23 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
24
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
25 public static JsonTextScanner Create(string file) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
26 return new JsonTextScanner(new StreamReader(file), new char[_bufferSize]);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
27 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
28
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
29 public static JsonTextScanner Create(Stream stream, Encoding encoding) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
30 return new JsonTextScanner(new StreamReader(stream, encoding), new char[_bufferSize]);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
31 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
32
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
33 public static JsonTextScanner Create(Stream stream) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
34 return new JsonTextScanner(new StreamReader(stream), new char[_bufferSize]);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
35 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
36
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
37 public static JsonTextScanner Create(TextReader reader) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
38 Safe.ArgumentNotNull(reader, nameof(reader));
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
39 return new JsonTextScanner(reader, new char[_bufferSize]);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
40 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
41
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
42 protected override void Dispose(bool disposing) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
43 if (disposing)
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
44 Safe.Dispose(m_reader);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
45
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
46 base.Dispose(disposing);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
47 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
48 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
49 }