Skip to content

Commit

Permalink
Update datatransfer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrserb committed Aug 22, 2021
1 parent 203366f commit 0d1d6d1
Showing 1 changed file with 19 additions and 12 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -51,6 +51,13 @@
import java.util.TreeSet;
import java.util.function.Supplier;

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_16;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_16LE;
import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Utility class with different datatransfer helper functions.
*
Expand Down Expand Up @@ -115,12 +122,12 @@ private static class StandardEncodingsHolder {

private static SortedSet<String> load() {
final SortedSet<String> tempSet = new TreeSet<>(getCharsetComparator().reversed());
tempSet.add("US-ASCII");
tempSet.add("ISO-8859-1");
tempSet.add("UTF-8");
tempSet.add("UTF-16BE");
tempSet.add("UTF-16LE");
tempSet.add("UTF-16");
tempSet.add(US_ASCII.name());
tempSet.add(ISO_8859_1.name());
tempSet.add(UTF_8.name());
tempSet.add(UTF_16BE.name());
tempSet.add(UTF_16LE.name());
tempSet.add(UTF_16.name());
tempSet.add(Charset.defaultCharset().name());
return Collections.unmodifiableSortedSet(tempSet);
}
Expand Down Expand Up @@ -318,13 +325,13 @@ private static class CharsetComparator implements Comparator<String> {
Map<String, Integer> charsetsMap = new HashMap<>(8, 1.0f);

// we prefer Unicode charsets
charsetsMap.put(canonicalName("UTF-16LE"), 4);
charsetsMap.put(canonicalName("UTF-16BE"), 5);
charsetsMap.put(canonicalName("UTF-8"), 6);
charsetsMap.put(canonicalName("UTF-16"), 7);
charsetsMap.put(UTF_16LE.name(), 4);
charsetsMap.put(UTF_16BE.name(), 5);
charsetsMap.put(UTF_8.name(), 6);
charsetsMap.put(UTF_16.name(), 7);

// US-ASCII is the worst charset supported
charsetsMap.put(canonicalName("US-ASCII"), WORST_CHARSET_INDEX);
charsetsMap.put(US_ASCII.name(), WORST_CHARSET_INDEX);

charsetsMap.putIfAbsent(Charset.defaultCharset().name(), DEFAULT_CHARSET_INDEX);

Expand Down

0 comments on commit 0d1d6d1

Please sign in to comment.