Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Library
Commits
2f6c9baa
Commit
2f6c9baa
authored
Jun 22, 2017
by
Karsten Loesing
Browse files
Always use UTF-8 as charset.
Implements
#21932
.
parent
a8622533
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
2f6c9baa
# Changes in version 2.0.0 - 2017-06-??
*
Major changes
-
Always use UTF-8 as charset rather than using the platform's
default charset.
*
Minor changes
-
Replace custom ImplementationNotAccessibleException thrown by
DescriptorSourceFactory with generic RuntimeException.
...
...
src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
View file @
2f6c9baa
...
...
@@ -8,6 +8,7 @@ import org.torproject.descriptor.DescriptorParseException;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
...
...
@@ -96,8 +97,8 @@ public abstract class DescriptorImpl implements Descriptor {
}
/**
* Returns a new {@link Scanner} for parsing the full raw descriptor s
tart
ing
*
using the platform's default
charset.
* Returns a new {@link Scanner} for parsing the full raw descriptor
u
sing
*
UTF-8 as
charset.
*
* @return Scanner for the full raw descriptor bytes.
*/
...
...
@@ -107,17 +108,16 @@ public abstract class DescriptorImpl implements Descriptor {
/**
* Returns a new {@link Scanner} for parsing the raw descriptor starting at
* byte <code>offset</code> containing <code>length</code> bytes using
the
*
platform's default
charset.
* byte <code>offset</code> containing <code>length</code> bytes using
UTF-8
*
as
charset.
*
* @param offset The index of the first byte to parse.
* @param length The number of bytes to parse.
* @return Scanner for the given raw descriptor bytes.
*/
protected
Scanner
newScanner
(
int
offset
,
int
length
)
{
/* XXX21932 */
return
new
Scanner
(
new
ByteArrayInputStream
(
this
.
rawDescriptorBytes
,
offset
,
length
));
return
new
Scanner
(
new
InputStreamReader
(
new
ByteArrayInputStream
(
this
.
rawDescriptorBytes
,
offset
,
length
),
StandardCharsets
.
UTF_8
));
}
/**
...
...
src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
View file @
2f6c9baa
...
...
@@ -8,6 +8,7 @@ import org.torproject.descriptor.DescriptorParseException;
import
org.torproject.descriptor.TorperfResult
;
import
java.io.File
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
...
...
@@ -27,8 +28,8 @@ public class TorperfResultImpl extends DescriptorImpl
throw
new
DescriptorParseException
(
"Descriptor is empty."
);
}
List
<
Descriptor
>
parsedDescriptors
=
new
ArrayList
<>();
/* XXX21932 */
String
descriptorString
=
new
String
(
rawDescriptorBytes
);
String
descriptorString
=
new
String
(
rawDescriptorBytes
,
StandardCharsets
.
UTF_8
);
Scanner
scanner
=
new
Scanner
(
descriptorString
).
useDelimiter
(
"\r?\n"
);
String
typeAnnotation
=
""
;
while
(
scanner
.
hasNext
())
{
...
...
@@ -48,8 +49,8 @@ public class TorperfResultImpl extends DescriptorImpl
}
else
{
/* XXX21932 */
parsedDescriptors
.
add
(
new
TorperfResultImpl
(
(
typeAnnotation
+
line
).
getBytes
(
),
descriptorFile
,
failUnrecognizedDescriptorLines
));
(
typeAnnotation
+
line
).
getBytes
(
StandardCharsets
.
UTF_8
)
,
descriptorFile
,
failUnrecognizedDescriptorLines
));
typeAnnotation
=
""
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment