1
1
package dev .ultreon .ubo ;
2
2
3
+ import dev .ultreon .ubo .types .DataType ;
3
4
import dev .ultreon .ubo .util .DataTypeVisitor ;
4
- import dev .ultreon .ubo .types .IType ;
5
5
6
6
import java .io .*;
7
7
import java .net .URL ;
@@ -15,14 +15,14 @@ public class DataIo {
15
15
private static final int BUFFER_SIZE = 4096 ;
16
16
17
17
@ SafeVarargs
18
- public static <T extends IType <?>> T read (File file , T ... type ) throws IOException {
18
+ public static <T extends DataType <?>> T read (File file , T ... type ) throws IOException {
19
19
try (InputStream stream = new BufferedInputStream (Files .newInputStream (file .toPath ()), BUFFER_SIZE )) {
20
20
return read (stream , type );
21
21
}
22
22
}
23
23
24
24
@ SafeVarargs
25
- public static <T extends IType <?>> T read (URL url , T ... type ) throws IOException {
25
+ public static <T extends DataType <?>> T read (URL url , T ... type ) throws IOException {
26
26
try (InputStream stream = new BufferedInputStream (url .openStream (), BUFFER_SIZE )) {
27
27
return read (stream , type );
28
28
}
@@ -33,7 +33,7 @@ public static <T extends IType<?>> T read(URL url, T... type) throws IOException
33
33
* @throws DataTypeException when the read data type is invalid.
34
34
*/
35
35
@ SafeVarargs
36
- public static <T extends IType <?>> T read (InputStream stream , T ... type ) throws IOException {
36
+ public static <T extends DataType <?>> T read (InputStream stream , T ... type ) throws IOException {
37
37
if (stream instanceof DataInput ) {
38
38
return read ((DataInput ) stream , type );
39
39
}
@@ -46,7 +46,7 @@ public static <T extends IType<?>> T read(InputStream stream, T... type) throws
46
46
*/
47
47
@ SafeVarargs
48
48
@ SuppressWarnings ("unchecked" )
49
- public static <T extends IType <?>> T read (DataInput input , T ... type ) throws IOException {
49
+ public static <T extends DataType <?>> T read (DataInput input , T ... type ) throws IOException {
50
50
int magic = input .readInt ();
51
51
if (magic != HEADER ) {
52
52
throw new StreamCorruptedException (String .format ("Invalid header got 0x%08X (expected 0xFF804269)" , magic ));
@@ -58,99 +58,99 @@ public static <T extends IType<?>> T read(DataInput input, T... type) throws IOE
58
58
}
59
59
60
60
Class <T > componentType = (Class <T >) type .getClass ().getComponentType ();
61
- int componentId = TypeRegistry .getId (componentType );
61
+ int componentId = DataTypeRegistry .getId (componentType );
62
62
int id = input .readUnsignedByte ();
63
63
64
64
if (componentId != id ) {
65
65
throw new DataTypeException ("The read data id " + id + " is different from the expected id: " + componentId );
66
66
}
67
67
68
- return (T ) TypeRegistry .read (id , input );
68
+ return (T ) DataTypeRegistry .read (id , input );
69
69
}
70
70
71
71
@ SafeVarargs
72
- public static <T extends IType <?>> T readCompressed (File file , T ... type ) throws IOException {
72
+ public static <T extends DataType <?>> T readCompressed (File file , T ... type ) throws IOException {
73
73
try (InputStream stream = new BufferedInputStream (Files .newInputStream (file .toPath ()), BUFFER_SIZE )) {
74
74
return readCompressed (stream , type );
75
75
}
76
76
}
77
77
78
78
@ SafeVarargs
79
- public static <T extends IType <?>> T readCompressed (URL url , T ... type ) throws IOException {
79
+ public static <T extends DataType <?>> T readCompressed (URL url , T ... type ) throws IOException {
80
80
try (InputStream stream = new BufferedInputStream (url .openStream ())) {
81
81
return readCompressed (stream , type );
82
82
}
83
83
}
84
84
85
85
@ SafeVarargs
86
- public static <T extends IType <?>> T readCompressed (InputStream stream , T ... type ) throws IOException {
86
+ public static <T extends DataType <?>> T readCompressed (InputStream stream , T ... type ) throws IOException {
87
87
GZIPInputStream gzipStream = new GZIPInputStream (stream );
88
88
return read (gzipStream , type );
89
89
}
90
90
91
- public static void write (IType <?> type , File file ) throws IOException {
91
+ public static void write (DataType <?> dataType , File file ) throws IOException {
92
92
try (OutputStream stream = new BufferedOutputStream (Files .newOutputStream (file .toPath ()), BUFFER_SIZE )) {
93
- write (type , stream );
93
+ write (dataType , stream );
94
94
}
95
95
}
96
96
97
- public static void write (IType <?> type , URL file ) throws IOException {
97
+ public static void write (DataType <?> dataType , URL file ) throws IOException {
98
98
try (OutputStream stream = new BufferedOutputStream (file .openConnection ().getOutputStream (), BUFFER_SIZE )) {
99
- write (type , stream );
99
+ write (dataType , stream );
100
100
}
101
101
}
102
102
103
- public static void write (IType <?> type , OutputStream stream ) throws IOException {
103
+ public static void write (DataType <?> dataType , OutputStream stream ) throws IOException {
104
104
if (stream instanceof DataOutput ) {
105
- write (type , (DataOutput ) stream );
105
+ write (dataType , (DataOutput ) stream );
106
106
}
107
- write (type , (DataOutput ) new DataOutputStream (stream ));
107
+ write (dataType , (DataOutput ) new DataOutputStream (stream ));
108
108
}
109
109
110
- public static void write (IType <?> type , DataOutput output ) throws IOException {
110
+ public static void write (DataType <?> dataType , DataOutput output ) throws IOException {
111
111
output .writeInt (HEADER );
112
112
output .writeShort (VERSION ); // Version
113
- output .writeByte (type .id ()); // Type
114
- type .write (output );
113
+ output .writeByte (dataType .id ()); // Type
114
+ dataType .write (output );
115
115
}
116
116
117
- public static void writeCompressed (IType <?> type , URL file ) throws IOException {
117
+ public static void writeCompressed (DataType <?> dataType , URL file ) throws IOException {
118
118
try (OutputStream stream = new BufferedOutputStream (file .openConnection ().getOutputStream (), BUFFER_SIZE )) {
119
- writeCompressed (type , stream );
119
+ writeCompressed (dataType , stream );
120
120
}
121
121
}
122
122
123
- public static void writeCompressed (IType <?> type , File file ) throws IOException {
123
+ public static void writeCompressed (DataType <?> dataType , File file ) throws IOException {
124
124
try (OutputStream stream = new BufferedOutputStream (Files .newOutputStream (file .toPath ()), BUFFER_SIZE )) {
125
- writeCompressed (type , stream );
125
+ writeCompressed (dataType , stream );
126
126
}
127
127
}
128
128
129
- public static void writeCompressed (IType <?> type , OutputStream stream ) throws IOException {
129
+ public static void writeCompressed (DataType <?> dataType , OutputStream stream ) throws IOException {
130
130
GZIPOutputStream gzipStream = new GZIPOutputStream (stream );
131
- write (type , gzipStream );
131
+ write (dataType , gzipStream );
132
132
gzipStream .finish ();
133
133
gzipStream .flush ();
134
134
}
135
135
136
- public static String toUso (IType <?> type ) {
137
- return type .writeUso ();
136
+ public static String toUso (DataType <?> dataType ) {
137
+ return dataType .writeUso ();
138
138
}
139
139
140
- public static <T > T visit (DataTypeVisitor <T > visitor , IType <?> type ) {
141
- return type .accept (visitor );
140
+ public static <T > T visit (DataTypeVisitor <T > visitor , DataType <?> dataType ) {
141
+ return dataType .accept (visitor );
142
142
}
143
143
144
144
@ SuppressWarnings ("unchecked" )
145
145
@ SafeVarargs
146
- public static <T extends IType <?>> T fromUso (String value , T ... type ) throws IOException {
146
+ public static <T extends DataType <?>> T fromUso (String value , T ... type ) throws IOException {
147
147
try (BufferedReader reader = new BufferedReader (new StringReader (value ))) {
148
- IType <?> iType = readUso (reader .readLine ());
149
- return (T ) iType ;
148
+ DataType <?> iDataType = readUso (reader .readLine ());
149
+ return (T ) iDataType ;
150
150
}
151
151
}
152
152
153
- private static IType <?> readUso (String value ) throws IOException {
153
+ private static DataType <?> readUso (String value ) throws IOException {
154
154
return new UsoParser (value ).parse ();
155
155
}
156
156
}
0 commit comments