[multiple changes]
2005-04-27 Michael Koch <konqueror@gmx.de> * java/nio/charset/Charset.java (providers2): Renamed from 'providers' to work around CNI limitation. 2005-04-27 Sven de Marothy <sven@physto.se> * java/nio/charset/Charset.java: (defaultCharset()): New method. Status updated to 1.5 2005-04-27 Sven de Marothy <sven@physto.se> * java/nio/charset/Charset.java: Cached encoders shouldn't be static. 2005-04-27 Sven de Marothy <sven@physto.se> * java/nio/charset/Charset.java: Reset cached de/encoders. 2005-04-27 Robert Schuster <thebohemian@gmx.net> * java/nio/charset/Charset.java (forName): Throws IllegalArgumentException when argument is null and added documentation. 2005-04-27 Ito Kazumitsu <kaz@maczuka.gcd.org> * java/nio/charset/Charset.java (providers): New method to make an array of CharsetProviders defined in META-INF/services/java.nio.charset.spi.CharsetProvider. (charsetForName, availableCharsets): Use the new method providers(). From-SVN: r98816
This commit is contained in:
parent
fbf5558065
commit
5984f98956
@ -1,3 +1,36 @@
|
||||
2005-04-27 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* java/nio/charset/Charset.java (providers2): Renamed from 'providers'
|
||||
to work around CNI limitation.
|
||||
|
||||
2005-04-27 Sven de Marothy <sven@physto.se>
|
||||
|
||||
* java/nio/charset/Charset.java:
|
||||
(defaultCharset()): New method.
|
||||
Status updated to 1.5
|
||||
|
||||
2005-04-27 Sven de Marothy <sven@physto.se>
|
||||
|
||||
* java/nio/charset/Charset.java: Cached encoders shouldn't be static.
|
||||
|
||||
2005-04-27 Sven de Marothy <sven@physto.se>
|
||||
|
||||
* java/nio/charset/Charset.java: Reset cached de/encoders.
|
||||
|
||||
2005-04-27 Robert Schuster <thebohemian@gmx.net>
|
||||
|
||||
* java/nio/charset/Charset.java (forName): Throws
|
||||
IllegalArgumentException when argument is null
|
||||
and added documentation.
|
||||
|
||||
2005-04-27 Ito Kazumitsu <kaz@maczuka.gcd.org>
|
||||
|
||||
* java/nio/charset/Charset.java (providers):
|
||||
New method to make an array of CharsetProviders defined in
|
||||
META-INF/services/java.nio.charset.spi.CharsetProvider.
|
||||
(charsetForName, availableCharsets): Use the
|
||||
new method providers().
|
||||
|
||||
2005-04-26 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* java/net/InetAddress.java: Made all hexadecimal numbers lowercase.
|
||||
|
@ -40,12 +40,17 @@ package java.nio.charset;
|
||||
|
||||
import gnu.java.nio.charset.Provider;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.spi.CharsetProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
@ -57,18 +62,14 @@ import java.util.TreeMap;
|
||||
*/
|
||||
public abstract class Charset implements Comparable
|
||||
{
|
||||
private static CharsetEncoder cachedEncoder;
|
||||
private static CharsetDecoder cachedDecoder;
|
||||
private CharsetEncoder cachedEncoder;
|
||||
private CharsetDecoder cachedDecoder;
|
||||
|
||||
static
|
||||
{
|
||||
synchronized (Charset.class)
|
||||
{
|
||||
cachedEncoder = null;
|
||||
cachedDecoder = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charset providers.
|
||||
*/
|
||||
private static CharsetProvider[] providers;
|
||||
|
||||
private final String canonicalName;
|
||||
private final String[] aliases;
|
||||
|
||||
@ -82,6 +83,8 @@ public abstract class Charset implements Comparable
|
||||
checkName (aliases[i]);
|
||||
}
|
||||
|
||||
cachedEncoder = null;
|
||||
cachedDecoder = null;
|
||||
this.canonicalName = canonicalName;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
@ -138,8 +141,6 @@ public abstract class Charset implements Comparable
|
||||
Charset cs = charsetForName (charsetName);
|
||||
if (cs == null)
|
||||
throw new UnsupportedCharsetException (charsetName);
|
||||
cachedDecoder = null;
|
||||
cachedEncoder = null;
|
||||
return cs;
|
||||
}
|
||||
|
||||
@ -154,30 +155,88 @@ public abstract class Charset implements Comparable
|
||||
private static Charset charsetForName(String charsetName)
|
||||
{
|
||||
checkName (charsetName);
|
||||
return provider ().charsetForName (charsetName);
|
||||
Charset cs = null;
|
||||
CharsetProvider[] providers = providers2();
|
||||
for (int i = 0; i < providers.length; i++)
|
||||
{
|
||||
cs = providers[i].charsetForName(charsetName);
|
||||
if (cs != null)
|
||||
break;
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
public static SortedMap availableCharsets()
|
||||
{
|
||||
TreeMap charsets = new TreeMap(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (Iterator i = provider ().charsets (); i.hasNext (); )
|
||||
CharsetProvider[] providers = providers2();
|
||||
for (int j = 0; j < providers.length; j++)
|
||||
{
|
||||
Charset cs = (Charset) i.next ();
|
||||
charsets.put (cs.name (), cs);
|
||||
for (Iterator i = providers[j].charsets(); i.hasNext(); )
|
||||
{
|
||||
Charset cs = (Charset) i.next();
|
||||
charsets.put(cs.name(), cs);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableSortedMap(charsets);
|
||||
}
|
||||
|
||||
// XXX: we need to support multiple providers, reading them from
|
||||
// java.nio.charset.spi.CharsetProvider in the resource directory
|
||||
// META-INF/services
|
||||
private static CharsetProvider provider()
|
||||
{
|
||||
try {
|
||||
String s = System.getProperty("charset.provider");
|
||||
if(s != null){
|
||||
CharsetProvider p =
|
||||
(CharsetProvider) ((Class.forName(s)).newInstance());
|
||||
return p;
|
||||
}
|
||||
} catch(Exception e){}
|
||||
return Provider.provider();
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to support multiple providers, reading them from
|
||||
* java.nio.charset.spi.CharsetProvider in the resource directory
|
||||
* META-INF/services.
|
||||
*/
|
||||
private static CharsetProvider[] providers2()
|
||||
{
|
||||
if (providers == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Enumeration en = ClassLoader.getSystemResources
|
||||
("META-INF/services/java.nio.charset.spi.CharsetProvider");
|
||||
LinkedHashSet set = new LinkedHashSet();
|
||||
set.add(provider());
|
||||
while (en.hasMoreElements())
|
||||
{
|
||||
BufferedReader rdr = new BufferedReader(new InputStreamReader
|
||||
(((URL) (en.nextElement())).openStream()));
|
||||
while (true)
|
||||
{
|
||||
String s = rdr.readLine();
|
||||
if (s == null)
|
||||
break;
|
||||
CharsetProvider p =
|
||||
(CharsetProvider) ((Class.forName(s)).newInstance());
|
||||
set.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
providers = new CharsetProvider[set.size()];
|
||||
set.toArray(providers);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
|
||||
public final String name ()
|
||||
{
|
||||
return canonicalName;
|
||||
@ -238,8 +297,8 @@ public abstract class Charset implements Comparable
|
||||
cachedEncoder = newEncoder ()
|
||||
.onMalformedInput (CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter (CodingErrorAction.REPLACE);
|
||||
}
|
||||
|
||||
} else
|
||||
cachedEncoder.reset();
|
||||
return cachedEncoder.encode (cb);
|
||||
}
|
||||
}
|
||||
@ -269,7 +328,8 @@ public abstract class Charset implements Comparable
|
||||
cachedDecoder = newDecoder ()
|
||||
.onMalformedInput (CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter (CodingErrorAction.REPLACE);
|
||||
}
|
||||
} else
|
||||
cachedDecoder.reset();
|
||||
|
||||
return cachedDecoder.decode (bb);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user