8271456: Avoid looking up standard charsets in "java.desktop" module

Reviewed-by: jdv, azvegint, aivanov
This commit is contained in:
Sergey Bylokhov 2021-08-04 18:44:18 +00:00
parent 392fcc9df7
commit 6b55ef3b58
33 changed files with 500 additions and 432 deletions

View File

@ -25,8 +25,11 @@
package com.apple.laf; package com.apple.laf;
import java.io.*; import java.io.File;
import java.util.*; import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.swing.Icon; import javax.swing.Icon;
@ -34,6 +37,8 @@ import javax.swing.filechooser.FileView;
import com.apple.laf.AquaUtils.RecyclableSingleton; import com.apple.laf.AquaUtils.RecyclableSingleton;
import static java.nio.charset.StandardCharsets.UTF_8;
@SuppressWarnings("serial") // JDK implementation class @SuppressWarnings("serial") // JDK implementation class
class AquaFileView extends FileView { class AquaFileView extends FileView {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
@ -111,11 +116,7 @@ class AquaFileView extends FileView {
FileInfo(final File file){ FileInfo(final File file){
isDirectory = file.isDirectory(); isDirectory = file.isDirectory();
absolutePath = file.getAbsolutePath(); absolutePath = file.getAbsolutePath();
try { pathBytes = absolutePath.getBytes(UTF_8);
pathBytes = absolutePath.getBytes("UTF-8");
} catch (final UnsupportedEncodingException e) {
pathBytes = new byte[0];
}
} }
} }

View File

@ -1,6 +1,5 @@
/* /*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,20 +25,27 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.*; import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.io.*; import java.awt.datatransfer.Transferable;
import java.net.URI; import java.awt.datatransfer.UnsupportedFlavorException;
import java.net.URISyntaxException; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.Normalizer; import java.text.Normalizer;
import java.text.Normalizer.Form; import java.text.Normalizer.Form;
import java.util.*; import java.util.ArrayList;
import java.util.regex.*; import java.util.Collections;
import java.awt.datatransfer.*; import java.util.HashMap;
import java.nio.charset.StandardCharsets; import java.util.Map;
import sun.awt.datatransfer.*; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
import static java.nio.charset.StandardCharsets.UTF_8;
public class CDataTransferer extends DataTransferer { public class CDataTransferer extends DataTransferer {
private static final Map<String, Long> predefinedClipboardNameMap; private static final Map<String, Long> predefinedClipboardNameMap;
@ -133,7 +139,7 @@ public class CDataTransferer extends DataTransferer {
String charset = Charset.defaultCharset().name(); String charset = Charset.defaultCharset().name();
if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) { if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
try { try {
charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), StandardCharsets.UTF_8); charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), UTF_8);
} catch (UnsupportedFlavorException cannotHappen) { } catch (UnsupportedFlavorException cannotHappen) {
} }
} }
@ -160,7 +166,8 @@ public class CDataTransferer extends DataTransferer {
// class by base method // class by base method
format = CF_STRING; format = CF_STRING;
} else if (format == CF_STRING) { } else if (format == CF_STRING) {
bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8"); String src = new String(bytes, UTF_8);
bytes = Normalizer.normalize(src, Form.NFC).getBytes(UTF_8);
} }
return super.translateBytes(bytes, flavor, format, transferable); return super.translateBytes(bytes, flavor, format, transferable);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,19 +25,15 @@
package com.sun.imageio.plugins.bmp; package com.sun.imageio.plugins.bmp;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node; import javax.imageio.metadata.IIOMetadataNode;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.ImageUtil; import com.sun.imageio.plugins.common.ImageUtil;
import org.w3c.dom.Node;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
public class BMPMetadata extends IIOMetadata implements BMPConstants { public class BMPMetadata extends IIOMetadata implements BMPConstants {
public static final String nativeMetadataFormatName = public static final String nativeMetadataFormatName =
@ -114,11 +110,7 @@ public class BMPMetadata extends IIOMetadata implements BMPConstants {
} }
private String toISO8859(byte[] data) { private String toISO8859(byte[] data) {
try { return new String(data, ISO_8859_1);
return new String(data, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "";
}
} }
private Node getNativeTree() { private Node getNativeTree() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,18 +25,17 @@
package com.sun.imageio.plugins.gif; package com.sun.imageio.plugins.gif;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
public class GIFImageMetadata extends GIFMetadata { public class GIFImageMetadata extends GIFMetadata {
// package scope // package scope
@ -132,11 +131,7 @@ public class GIFImageMetadata extends GIFMetadata {
} }
private String toISO8859(byte[] data) { private String toISO8859(byte[] data) {
try { return new String(data, ISO_8859_1);
return new String(data, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "";
}
} }
private Node getNativeTree() { private Node getNativeTree() {
@ -384,12 +379,7 @@ public class GIFImageMetadata extends GIFMetadata {
while (commentIter.hasNext()) { while (commentIter.hasNext()) {
byte[] comment = commentIter.next(); byte[] comment = commentIter.next();
String s = null; String s = new String(comment, ISO_8859_1);
try {
s = new String(comment, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Encoding ISO-8859-1 unknown!");
}
node = new IIOMetadataNode("TextEntry"); node = new IIOMetadataNode("TextEntry");
node.setAttribute("value", s); node.setAttribute("value", s);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,19 +25,17 @@
package com.sun.imageio.plugins.gif; package com.sun.imageio.plugins.gif;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
class GIFWritableImageMetadata extends GIFImageMetadata { class GIFWritableImageMetadata extends GIFImageMetadata {
// package scope // package scope
@ -95,11 +93,7 @@ class GIFWritableImageMetadata extends GIFImageMetadata {
} }
private byte[] fromISO8859(String data) { private byte[] fromISO8859(String data) {
try { return data.getBytes(ISO_8859_1);
return data.getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "".getBytes();
}
} }
protected void mergeNativeTree(Node root) throws IIOInvalidTreeException { protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,15 +25,16 @@
package com.sun.imageio.plugins.jpeg; package com.sun.imageio.plugins.jpeg;
import java.io.IOException;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode; import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.ImageOutputStream;
import javax.imageio.metadata.IIOInvalidTreeException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/** /**
* A Comment marker segment. Retains an array of bytes representing the * A Comment marker segment. Retains an array of bytes representing the
* comment data as it is read from the stream. If the marker segment is * comment data as it is read from the stream. If the marker segment is
@ -45,7 +46,6 @@ import org.w3c.dom.Node;
* byte array, again assuming the default local encoding. * byte array, again assuming the default local encoding.
*/ */
class COMMarkerSegment extends MarkerSegment { class COMMarkerSegment extends MarkerSegment {
private static final String ENCODING = "ISO-8859-1";
/** /**
* Constructs a marker segment from the given buffer, which contains * Constructs a marker segment from the given buffer, which contains
@ -96,10 +96,7 @@ class COMMarkerSegment extends MarkerSegment {
* consulted directly. * consulted directly.
*/ */
String getComment() { String getComment() {
try { return new String(data, ISO_8859_1);
return new String (data, ENCODING);
} catch (UnsupportedEncodingException e) {} // Won't happen
return null;
} }
/** /**

View File

@ -25,40 +25,41 @@
package com.sun.imageio.plugins.jpeg; package com.sun.imageio.plugins.jpeg;
import java.awt.Graphics;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.IIOException; import javax.imageio.IIOException;
import javax.imageio.IIOImage; import javax.imageio.IIOImage;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageReader; import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.event.IIOReadProgressListener;
import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode; import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream; import javax.imageio.stream.MemoryCacheImageOutputStream;
import javax.imageio.event.IIOReadProgressListener;
import java.awt.Graphics;
import java.awt.color.ICC_Profile;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ColorSpace;
import java.awt.image.ColorModel;
import java.awt.image.SampleModel;
import java.awt.image.IndexColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* A JFIF (JPEG File Interchange Format) APP0 (Application-Specific) * A JFIF (JPEG File Interchange Format) APP0 (Application-Specific)
@ -1353,7 +1354,7 @@ class JFIFMarkerSegment extends MarkerSegment {
ios.write(0xff); ios.write(0xff);
ios.write(JPEG.APP2); ios.write(JPEG.APP2);
MarkerSegment.write2bytes(ios, segLength); MarkerSegment.write2bytes(ios, segLength);
byte [] id = ID.getBytes("US-ASCII"); byte[] id = ID.getBytes(US_ASCII);
ios.write(id); ios.write(id);
ios.write(0); // Null-terminate the string ios.write(0); // Null-terminate the string
ios.write(chunkNum++); ios.write(chunkNum++);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,10 +36,11 @@ import java.awt.image.Raster;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.EOFException; import java.io.EOFException;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream; import java.io.SequenceInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -47,19 +48,23 @@ import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import java.util.zip.Inflater; import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
import javax.imageio.IIOException; import javax.imageio.IIOException;
import javax.imageio.ImageReader;
import javax.imageio.ImageReadParam; import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadata;
import javax.imageio.spi.ImageReaderSpi; import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
import com.sun.imageio.plugins.common.InputStreamAdapter; import com.sun.imageio.plugins.common.InputStreamAdapter;
import com.sun.imageio.plugins.common.ReaderUtil; import com.sun.imageio.plugins.common.ReaderUtil;
import com.sun.imageio.plugins.common.SubImageInputStream; import com.sun.imageio.plugins.common.SubImageInputStream;
import java.io.ByteArrayOutputStream;
import sun.awt.image.ByteInterleavedRaster; import sun.awt.image.ByteInterleavedRaster;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
class PNGImageDataEnumeration implements Enumeration<InputStream> { class PNGImageDataEnumeration implements Enumeration<InputStream> {
boolean firstTime = true; boolean firstTime = true;
@ -486,9 +491,9 @@ public class PNGImageReader extends ImageReader {
stream.readFully(b); stream.readFully(b);
if (compressionFlag == 1) { // Decompress the text if (compressionFlag == 1) { // Decompress the text
text = new String(inflate(b), "UTF8"); text = new String(inflate(b), UTF_8);
} else { } else {
text = new String(b, "UTF8"); text = new String(b, UTF_8);
} }
metadata.iTXt_text.add(text); metadata.iTXt_text.add(text);
@ -589,7 +594,7 @@ public class PNGImageReader extends ImageReader {
byte[] b = new byte[textLength]; byte[] b = new byte[textLength];
stream.readFully(b); stream.readFully(b);
metadata.tEXt_text.add(new String(b, "ISO-8859-1")); metadata.tEXt_text.add(new String(b, ISO_8859_1));
// Check if the text chunk contains image creation time // Check if the text chunk contains image creation time
if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) { if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {
@ -690,7 +695,7 @@ public class PNGImageReader extends ImageReader {
byte[] b = new byte[textLength]; byte[] b = new byte[textLength];
stream.readFully(b); stream.readFully(b);
metadata.zTXt_text.add(new String(inflate(b), "ISO-8859-1")); metadata.zTXt_text.add(new String(inflate(b), ISO_8859_1));
// Check if the text chunk contains image creation time // Check if the text chunk contains image creation time
if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) { if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,15 +28,16 @@ package com.sun.imageio.plugins.png;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.IndexColorModel; import java.awt.image.IndexColorModel;
import java.awt.image.Raster; import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.awt.image.RenderedImage; import java.awt.image.RenderedImage;
import java.awt.image.SampleModel; import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream; import java.util.zip.DeflaterOutputStream;
import javax.imageio.IIOException; import javax.imageio.IIOException;
import javax.imageio.IIOImage; import javax.imageio.IIOImage;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
@ -47,6 +48,9 @@ import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.ImageOutputStreamImpl; import javax.imageio.stream.ImageOutputStreamImpl;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
final class CRC { final class CRC {
private static final int[] crcTable = new int[256]; private static final int[] crcTable = new int[256];
@ -801,15 +805,14 @@ public final class PNGImageWriter extends ImageWriter {
cs.writeBytes(languageIter.next()); cs.writeBytes(languageIter.next());
cs.writeByte(0); cs.writeByte(0);
cs.write(translatedKeywordIter.next().getBytes(UTF_8));
cs.write(translatedKeywordIter.next().getBytes("UTF8"));
cs.writeByte(0); cs.writeByte(0);
String text = textIter.next(); String text = textIter.next();
if (compressed) { if (compressed) {
cs.write(deflate(text.getBytes("UTF8"))); cs.write(deflate(text.getBytes(UTF_8)));
} else { } else {
cs.write(text.getBytes("UTF8")); cs.write(text.getBytes(UTF_8));
} }
cs.finish(); cs.finish();
} }
@ -833,7 +836,7 @@ public final class PNGImageWriter extends ImageWriter {
cs.writeByte(compressionMethod); cs.writeByte(compressionMethod);
String text = textIter.next(); String text = textIter.next();
cs.write(deflate(text.getBytes("ISO-8859-1"))); cs.write(deflate(text.getBytes(ISO_8859_1)));
cs.finish(); cs.finish();
} }
} }

View File

@ -22,24 +22,27 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package com.sun.imageio.plugins.tiff; package com.sun.imageio.plugins.tiff;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.imageio.IIOException; import javax.imageio.IIOException;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.plugins.tiff.BaselineTIFFTagSet; import javax.imageio.plugins.tiff.BaselineTIFFTagSet;
import javax.imageio.plugins.tiff.TIFFDirectory; import javax.imageio.plugins.tiff.TIFFDirectory;
import javax.imageio.plugins.tiff.TIFFField; import javax.imageio.plugins.tiff.TIFFField;
import javax.imageio.plugins.tiff.TIFFTag; import javax.imageio.plugins.tiff.TIFFTag;
import javax.imageio.plugins.tiff.TIFFTagSet; import javax.imageio.plugins.tiff.TIFFTagSet;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import static java.nio.charset.StandardCharsets.US_ASCII;
public class TIFFIFD extends TIFFDirectory { public class TIFFIFD extends TIFFDirectory {
private static final long MAX_SAMPLES_PER_PIXEL = 0xffff; private static final long MAX_SAMPLES_PER_PIXEL = 0xffff;
@ -283,8 +286,7 @@ public class TIFFIFD extends TIFFDirectory {
if (inString) { if (inString) {
// end of string // end of string
String s = new String(bvalues, prevIndex, String s = new String(bvalues, prevIndex,
index - prevIndex, index - prevIndex, US_ASCII);
StandardCharsets.US_ASCII);
v.add(s); v.add(s);
inString = false; inString = false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,6 +22,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package com.sun.imageio.plugins.tiff; package com.sun.imageio.plugins.tiff;
import java.awt.Point; import java.awt.Point;
@ -34,8 +35,8 @@ import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer; import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte; import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel; import java.awt.image.IndexColorModel;
import java.awt.image.RenderedImage;
import java.awt.image.Raster; import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel; import java.awt.image.SampleModel;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.io.EOFException; import java.io.EOFException;
@ -44,27 +45,30 @@ import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.imageio.IIOException; import javax.imageio.IIOException;
import javax.imageio.IIOImage; import javax.imageio.IIOImage;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
import org.w3c.dom.Node;
import com.sun.imageio.plugins.common.ImageUtil;
import javax.imageio.plugins.tiff.BaselineTIFFTagSet; import javax.imageio.plugins.tiff.BaselineTIFFTagSet;
import javax.imageio.plugins.tiff.ExifParentTIFFTagSet; import javax.imageio.plugins.tiff.ExifParentTIFFTagSet;
import javax.imageio.plugins.tiff.ExifTIFFTagSet; import javax.imageio.plugins.tiff.ExifTIFFTagSet;
import javax.imageio.plugins.tiff.TIFFField; import javax.imageio.plugins.tiff.TIFFField;
import javax.imageio.plugins.tiff.TIFFTag; import javax.imageio.plugins.tiff.TIFFTag;
import javax.imageio.plugins.tiff.TIFFTagSet; import javax.imageio.plugins.tiff.TIFFTagSet;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
import com.sun.imageio.plugins.common.ImageUtil;
import com.sun.imageio.plugins.common.SimpleRenderedImage; import com.sun.imageio.plugins.common.SimpleRenderedImage;
import com.sun.imageio.plugins.common.SingleTileRenderedImage; import com.sun.imageio.plugins.common.SingleTileRenderedImage;
import java.nio.charset.StandardCharsets; import org.w3c.dom.Node;
import static java.nio.charset.StandardCharsets.US_ASCII;
public class TIFFImageWriter extends ImageWriter { public class TIFFImageWriter extends ImageWriter {
@ -1512,7 +1516,7 @@ public class TIFFImageWriter extends ImageWriter {
(exifTags.getTag(ExifTIFFTagSet.TAG_EXIF_VERSION), (exifTags.getTag(ExifTIFFTagSet.TAG_EXIF_VERSION),
TIFFTag.TIFF_UNDEFINED, TIFFTag.TIFF_UNDEFINED,
4, 4,
ExifTIFFTagSet.EXIF_VERSION_2_2.getBytes(StandardCharsets.US_ASCII)); ExifTIFFTagSet.EXIF_VERSION_2_2.getBytes(US_ASCII));
exifIFD.addTIFFField(f); exifIFD.addTIFFField(f);
} }

View File

@ -25,19 +25,13 @@
package com.sun.imageio.plugins.wbmp; package com.sun.imageio.plugins.wbmp;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node; import javax.imageio.metadata.IIOMetadataNode;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.ImageUtil; import com.sun.imageio.plugins.common.ImageUtil;
import org.w3c.dom.Node;
public class WBMPMetadata extends IIOMetadata { public class WBMPMetadata extends IIOMetadata {

View File

@ -22,29 +22,76 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package com.sun.java.swing.plaf.gtk; package com.sun.java.swing.plaf.gtk;
import sun.swing.SwingUtilities2; import java.awt.AlphaComposite;
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType; import java.awt.BasicStroke;
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType; import java.awt.Color;
import java.awt.Component;
import java.awt.Composite;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.synth.*; import javax.swing.plaf.synth.ColorType;
import javax.swing.plaf.synth.SynthConstants;
import javax.swing.plaf.synth.SynthContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.awt.*; import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
import java.awt.geom.*; import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
import java.awt.image.*; import org.w3c.dom.Document;
import java.io.*; import org.w3c.dom.NamedNodeMap;
import java.net.*; import org.w3c.dom.Node;
import java.security.*; import org.w3c.dom.NodeList;
import java.util.*;
import javax.swing.*;
import javax.xml.parsers.*;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.w3c.dom.*; import sun.swing.SwingUtilities2;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/** /**
*/ */
@ -536,7 +583,8 @@ class Metacity implements SynthConstants {
URL url = new URL(new File(userHome).toURI().toURL(), URL url = new URL(new File(userHome).toURI().toURL(),
".gconf/apps/metacity/general/%25gconf.xml"); ".gconf/apps/metacity/general/%25gconf.xml");
// Pending: verify character encoding spec for gconf // Pending: verify character encoding spec for gconf
Reader reader = new InputStreamReader(url.openStream(), "ISO-8859-1"); Reader reader = new InputStreamReader(url.openStream(),
ISO_8859_1);
char[] buf = new char[1024]; char[] buf = new char[1024];
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int n; int n;

View File

@ -47,6 +47,8 @@ import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* A DLS Level 1 and Level 2 soundbank reader (from files/url/streams). * A DLS Level 1 and Level 2 soundbank reader (from files/url/streams).
* *
@ -1147,7 +1149,7 @@ public final class DLSSoundbank implements Soundbank {
return; return;
RIFFWriter chunk = writer.writeChunk(name); RIFFWriter chunk = writer.writeChunk(name);
chunk.writeString(value); chunk.writeString(value);
int len = value.getBytes("ascii").length; int len = value.getBytes(US_ASCII).length;
chunk.write(0); chunk.write(0);
len++; len++;
if (len % 2 != 0) if (len % 2 != 0)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,8 @@ import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* Resource Interchange File Format (RIFF) stream decoder. * Resource Interchange File Format (RIFF) stream decoder.
* *
@ -76,14 +78,14 @@ public final class RIFFReader extends InputStream {
byte[] fourcc = new byte[4]; byte[] fourcc = new byte[4];
fourcc[0] = (byte) b; fourcc[0] = (byte) b;
readFully(fourcc, 1, 3); readFully(fourcc, 1, 3);
this.fourcc = new String(fourcc, "ascii"); this.fourcc = new String(fourcc, US_ASCII);
ckSize = readUnsignedInt(); ckSize = readUnsignedInt();
avail = ckSize; avail = ckSize;
if (getFormat().equals("RIFF") || getFormat().equals("LIST")) { if (getFormat().equals("RIFF") || getFormat().equals("LIST")) {
byte[] format = new byte[4]; byte[] format = new byte[4];
readFully(format); readFully(format);
this.riff_type = new String(format, "ascii"); this.riff_type = new String(format, US_ASCII);
} }
} }
@ -227,10 +229,10 @@ public final class RIFFReader extends InputStream {
readFully(buff); readFully(buff);
for (int i = 0; i < buff.length; i++) { for (int i = 0; i < buff.length; i++) {
if (buff[i] == 0) { if (buff[i] == 0) {
return new String(buff, 0, i, "ascii"); return new String(buff, 0, i, US_ASCII);
} }
} }
return new String(buff, "ascii"); return new String(buff, US_ASCII);
} }
// Read 8 bit signed integer from stream // Read 8 bit signed integer from stream

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,8 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* Resource Interchange File Format (RIFF) stream encoder. * Resource Interchange File Format (RIFF) stream encoder.
* *
@ -208,11 +210,11 @@ public final class RIFFWriter extends OutputStream {
raf.write(0); raf.write(0);
if (chunktype == 0) if (chunktype == 0)
raf.write("RIFF".getBytes("ascii")); raf.write("RIFF".getBytes(US_ASCII));
else if (chunktype == 1) else if (chunktype == 1)
raf.write("LIST".getBytes("ascii")); raf.write("LIST".getBytes(US_ASCII));
else else
raf.write((format + " ").substring(0, 4).getBytes("ascii")); raf.write((format + " ").substring(0, 4).getBytes(US_ASCII));
chunksizepointer = raf.getPointer(); chunksizepointer = raf.getPointer();
this.chunktype = 2; this.chunktype = 2;
@ -220,8 +222,7 @@ public final class RIFFWriter extends OutputStream {
this.chunktype = chunktype; this.chunktype = chunktype;
startpointer = raf.getPointer(); startpointer = raf.getPointer();
if (chunktype != 2) if (chunktype != 2)
raf.write((format + " ").substring(0, 4).getBytes("ascii")); raf.write((format + " ").substring(0, 4).getBytes(US_ASCII));
} }
public void seek(long pos) throws IOException { public void seek(long pos) throws IOException {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,6 +42,8 @@ import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank; import javax.sound.midi.Soundbank;
import javax.sound.midi.SoundbankResource; import javax.sound.midi.SoundbankResource;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* A SoundFont 2.04 soundbank reader. * A SoundFont 2.04 soundbank reader.
* *
@ -539,7 +541,7 @@ public final class SF2Soundbank implements Soundbank {
return; return;
RIFFWriter chunk = writer.writeChunk(name); RIFFWriter chunk = writer.writeChunk(name);
chunk.writeString(value); chunk.writeString(value);
int len = value.getBytes("ascii").length; int len = value.getBytes(US_ASCII).length;
chunk.write(0); chunk.write(0);
len++; len++;
if (len % 2 != 0) if (len % 2 != 0)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,12 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.io.UnsupportedEncodingException;
import java.util.Arrays; import java.util.Arrays;
import javax.sound.midi.Patch; import javax.sound.midi.Patch;
import static java.nio.charset.StandardCharsets.US_ASCII;
/** /**
* A tuning program container, for use with MIDI Tuning. * A tuning program container, for use with MIDI Tuning.
* See: http://www.midi.org * See: http://www.midi.org
@ -99,11 +100,7 @@ public final class SoftTuning {
// http://www.midi.org/about-midi/tuning.shtml // http://www.midi.org/about-midi/tuning.shtml
//if (!checksumOK2(data)) //if (!checksumOK2(data))
// break; // break;
try { name = new String(data, 6, 16, US_ASCII);
name = new String(data, 6, 16, "ascii");
} catch (UnsupportedEncodingException e) {
name = null;
}
int r = 22; int r = 22;
for (int i = 0; i < 128; i++) { for (int i = 0; i < 128; i++) {
int xx = data[r++] & 0xFF; int xx = data[r++] & 0xFF;
@ -135,11 +132,7 @@ public final class SoftTuning {
// http://www.midi.org/about-midi/tuning_extens.shtml // http://www.midi.org/about-midi/tuning_extens.shtml
if (!checksumOK(data)) if (!checksumOK(data))
break; break;
try { name = new String(data, 7, 16, US_ASCII);
name = new String(data, 7, 16, "ascii");
} catch (UnsupportedEncodingException e) {
name = null;
}
int r = 23; int r = 23;
for (int i = 0; i < 128; i++) { for (int i = 0; i < 128; i++) {
int xx = data[r++] & 0xFF; int xx = data[r++] & 0xFF;
@ -156,11 +149,7 @@ public final class SoftTuning {
// http://www.midi.org/about-midi/tuning_extens.shtml // http://www.midi.org/about-midi/tuning_extens.shtml
if (!checksumOK(data)) if (!checksumOK(data))
break; break;
try { name = new String(data, 7, 16, US_ASCII);
name = new String(data, 7, 16, "ascii");
} catch (UnsupportedEncodingException e) {
name = null;
}
int[] octave_tuning = new int[12]; int[] octave_tuning = new int[12];
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
octave_tuning[i] = (data[i + 23] & 0xFF) - 64; octave_tuning[i] = (data[i + 23] & 0xFF) - 64;
@ -174,11 +163,7 @@ public final class SoftTuning {
// http://www.midi.org/about-midi/tuning_extens.shtml // http://www.midi.org/about-midi/tuning_extens.shtml
if (!checksumOK(data)) if (!checksumOK(data))
break; break;
try { name = new String(data, 7, 16, US_ASCII);
name = new String(data, 7, 16, "ascii");
} catch (UnsupportedEncodingException e) {
name = null;
}
double[] octave_tuning = new double[12]; double[] octave_tuning = new double[12];
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
int v = (data[i * 2 + 23] & 0xFF) * 128 int v = (data[i * 2 + 23] & 0xFF) * 128

View File

@ -22,25 +22,81 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package javax.swing.text.html; package javax.swing.text.html;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
import java.io.Writer;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JViewport;
import javax.swing.SizeRequirements;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.HyperlinkEvent;
import javax.swing.plaf.TextUI;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.BoxView;
import javax.swing.text.ComponentView;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import javax.swing.text.Highlighter;
import javax.swing.text.IconView;
import javax.swing.text.JTextComponent;
import javax.swing.text.LabelView;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.Position;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.TextAction;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.parser.ParserDelegator;
import sun.awt.AppContext; import sun.awt.AppContext;
import java.awt.*; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import java.awt.event.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.TextUI;
import java.util.*;
import javax.accessibility.*;
import java.lang.ref.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.text.html.parser.ParserDelegator;
/** /**
* The Swing JEditorPane text component supports different kinds * The Swing JEditorPane text component supports different kinds
@ -403,7 +459,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
try { try {
InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS); InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS);
Reader r = new BufferedReader( Reader r = new BufferedReader(
new InputStreamReader(is, "ISO-8859-1")); new InputStreamReader(is, ISO_8859_1));
defaultStyles.loadRules(r, null); defaultStyles.loadRules(r, null);
r.close(); r.close();
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -22,15 +22,34 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package javax.swing.text.rtf; package javax.swing.text.rtf;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.awt.Color; import java.awt.Color;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StreamTokenizer;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import javax.swing.text.*; import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import javax.swing.text.TabStop;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/** /**
* Takes a sequence of RTF tokens and text and appends the text * Takes a sequence of RTF tokens and text and appends the text
@ -592,7 +611,7 @@ static char[] readCharset(InputStream strm)
char[] values = new char[256]; char[] values = new char[256];
int i; int i;
StreamTokenizer in = new StreamTokenizer(new BufferedReader( StreamTokenizer in = new StreamTokenizer(new BufferedReader(
new InputStreamReader(strm, "ISO-8859-1"))); new InputStreamReader(strm, ISO_8859_1)));
in.eolIsSignificant(false); in.eolIsSignificant(false);
in.commentChar('#'); in.commentChar('#');

View File

@ -22,14 +22,17 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package sun.awt; package sun.awt;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import static java.nio.charset.StandardCharsets.UTF_16BE;
import static java.nio.charset.StandardCharsets.UTF_16LE;
public class FontDescriptor implements Cloneable { public class FontDescriptor implements Cloneable {
@ -109,9 +112,8 @@ public class FontDescriptor implements Cloneable {
public boolean useUnicode() { public boolean useUnicode() {
if (useUnicode && unicodeEncoder == null) { if (useUnicode && unicodeEncoder == null) {
try { try {
this.unicodeEncoder = isLE? this.unicodeEncoder = isLE ? UTF_16LE.newEncoder():
StandardCharsets.UTF_16LE.newEncoder(): UTF_16BE.newEncoder();
StandardCharsets.UTF_16BE.newEncoder();
} catch (IllegalArgumentException x) {} } catch (IllegalArgumentException x) {}
} }
return useUnicode; return useUnicode;

View File

@ -29,77 +29,78 @@ import java.awt.EventQueue;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorMap; import java.awt.datatransfer.FlavorMap;
import java.awt.datatransfer.FlavorTable; import java.awt.datatransfer.FlavorTable;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.SequenceInputStream; import java.io.SequenceInputStream;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.stream.Stream;
import java.util.*; import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import sun.datatransfer.DataFlavorUtil; import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriter;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.ComponentFactory; import sun.awt.ComponentFactory;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
import java.awt.image.ColorModel;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import sun.awt.image.ImageRepresentation; import sun.awt.image.ImageRepresentation;
import sun.awt.image.ToolkitImage; import sun.awt.image.ToolkitImage;
import sun.datatransfer.DataFlavorUtil;
import java.io.FilePermission; import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.stream.Stream;
/** /**
* Provides a set of functions to be shared among the DataFlavor class and * Provides a set of functions to be shared among the DataFlavor class and
@ -550,7 +551,7 @@ public abstract class DataTransferer {
try { try {
byte[] charsetNameBytes = (byte[])localeTransferable byte[] charsetNameBytes = (byte[])localeTransferable
.getTransferData(javaTextEncodingFlavor); .getTransferData(javaTextEncodingFlavor);
charset = new String(charsetNameBytes, StandardCharsets.UTF_8); charset = new String(charsetNameBytes, UTF_8);
} catch (UnsupportedFlavorException cannotHappen) { } catch (UnsupportedFlavorException cannotHappen) {
} }
} else { } else {

View File

@ -25,23 +25,23 @@
package sun.font; package sun.font;
import java.lang.ref.WeakReference;
import java.awt.FontFormatException; import java.awt.FontFormatException;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.BufferUnderflowException;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.HashSet;
import sun.java2d.Disposer; import sun.java2d.Disposer;
import sun.java2d.DisposerRecord; import sun.java2d.DisposerRecord;
import java.util.HashSet;
import java.util.HashMap; import static java.nio.charset.StandardCharsets.US_ASCII;
import java.awt.Font;
/* /*
* Adobe Technical Note 5040 details the format of PFB files. * Adobe Technical Note 5040 details the format of PFB files.
@ -609,11 +609,7 @@ public class Type1Font extends FileFont {
byte[] nameBytes = new byte[pos2-pos1-1]; byte[] nameBytes = new byte[pos2-pos1-1];
bb.position(pos1); bb.position(pos1);
bb.get(nameBytes); bb.get(nameBytes);
try { return new String(nameBytes, US_ASCII);
return new String(nameBytes, "US-ASCII");
} catch (UnsupportedEncodingException e) {
return new String(nameBytes);
}
} }
private String getString(ByteBuffer bb) { private String getString(ByteBuffer bb) {
@ -623,11 +619,7 @@ public class Type1Font extends FileFont {
byte[] nameBytes = new byte[pos2-pos1-1]; byte[] nameBytes = new byte[pos2-pos1-1];
bb.position(pos1); bb.position(pos1);
bb.get(nameBytes); bb.get(nameBytes);
try { return new String(nameBytes, US_ASCII);
return new String(nameBytes, "US-ASCII");
} catch (UnsupportedEncodingException e) {
return new String(nameBytes);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,10 @@
package sun.print; package sun.print;
import java.awt.print.Pageable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.awt.print.Pageable;
import javax.print.Doc; import javax.print.Doc;
import javax.print.DocFlavor; import javax.print.DocFlavor;
@ -57,9 +55,7 @@ public class PageableDoc implements Doc {
return pageable; return pageable;
} }
public Reader getReaderForText() public Reader getReaderForText() throws IOException {
throws UnsupportedEncodingException, IOException {
return null; return null;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,9 +58,13 @@ package sun.awt.X11;
* @since 1.5 * @since 1.5
*/ */
import jdk.internal.misc.Unsafe;
import java.util.HashMap; import java.util.HashMap;
import jdk.internal.misc.Unsafe;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
public final class XAtom { public final class XAtom {
// Order of lock: XAWTLock -> XAtom.class // Order of lock: XAWTLock -> XAtom.class
@ -308,12 +312,7 @@ public final class XAtom {
throw new IllegalStateException("Atom should be initialized"); throw new IllegalStateException("Atom should be initialized");
} }
checkWindow(window); checkWindow(window);
byte[] bdata = null; byte[] bdata = str.getBytes(UTF_8);
try {
bdata = str.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
uee.printStackTrace();
}
if (bdata != null) { if (bdata != null) {
setAtomData(window, XA_UTF8_STRING.atom, bdata); setAtomData(window, XA_UTF8_STRING.atom, bdata);
} }
@ -327,12 +326,7 @@ public final class XAtom {
throw new IllegalStateException("Atom should be initialized"); throw new IllegalStateException("Atom should be initialized");
} }
checkWindow(window); checkWindow(window);
byte[] bdata = null; byte[] bdata = str.getBytes(ISO_8859_1);
try {
bdata = str.getBytes("ISO-8859-1");
} catch (java.io.UnsupportedEncodingException uee) {
uee.printStackTrace();
}
if (bdata != null) { if (bdata != null) {
setAtomData(window, XA_STRING, bdata); setAtomData(window, XA_STRING, bdata);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,14 +23,17 @@
* questions. * questions.
*/ */
package sun.awt.X11; package sun.awt.X11;
import java.awt.Frame; import java.awt.Frame;
import java.nio.charset.Charset;
import sun.awt.IconInfo; import sun.awt.IconInfo;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol
{ {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XNETProtocol"); private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XNETProtocol");
@ -382,22 +385,18 @@ final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProt
* mandates UTF8_STRING for _NET_WM_NAME but at least sawfish-1.0 * mandates UTF8_STRING for _NET_WM_NAME but at least sawfish-1.0
* still uses STRING. (mmm, moving targets...). * still uses STRING. (mmm, moving targets...).
*/ */
String charSet = "UTF8"; Charset charSet = UTF_8;
byte[] net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XA_UTF8_STRING.getAtom()); byte[] net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XA_UTF8_STRING.getAtom());
if (net_wm_name == null) { if (net_wm_name == null) {
net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XAtom.XA_STRING); net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XAtom.XA_STRING);
charSet = "ASCII"; charSet = US_ASCII;
} }
if (net_wm_name == null) { if (net_wm_name == null) {
return null; return null;
} }
try { net_wm_name_cache = new String(net_wm_name, charSet);
net_wm_name_cache = new String(net_wm_name, charSet); return net_wm_name_cache;
return net_wm_name_cache;
} catch (java.io.UnsupportedEncodingException uex) {
return null;
}
} }
/** /**

View File

@ -47,7 +47,6 @@ import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.peer.ComponentPeer; import java.awt.peer.ComponentPeer;
import java.awt.peer.WindowPeer; import java.awt.peer.WindowPeer;
import java.io.UnsupportedEncodingException;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
@ -67,6 +66,8 @@ import sun.awt.X11GraphicsEnvironment;
import sun.java2d.pipe.Region; import sun.java2d.pipe.Region;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import static java.nio.charset.StandardCharsets.UTF_8;
class XWindowPeer extends XPanelPeer implements WindowPeer, class XWindowPeer extends XPanelPeer implements WindowPeer,
DisplayChangedListener { DisplayChangedListener {
@ -1358,12 +1359,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
} }
messageBuilder.append('"'); messageBuilder.append('"');
messageBuilder.append('\0'); messageBuilder.append('\0');
final byte[] message; final byte[] message = messageBuilder.toString().getBytes(UTF_8);
try {
message = messageBuilder.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException cannotHappen) {
return;
}
XClientMessageEvent req = null; XClientMessageEvent req = null;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,12 +26,10 @@
package sun.awt; package sun.awt;
import java.awt.Color; import java.awt.Color;
import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Per-screen XSETTINGS. * Per-screen XSETTINGS.
@ -198,12 +196,7 @@ public class XSettings {
{ {
needBytes(len); needBytes(len);
String str = null; String str = new String(data, idx, len, UTF_8);
try {
str = new String(data, idx, len, "UTF-8");
} catch (UnsupportedEncodingException e) {
// XXX: cannot happen, "UTF-8" is always supported
}
idx = (idx + len + 3) & ~0x3; idx = (idx + len + 3) & ~0x3;
return str; return str;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,23 +32,24 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.Scanner; import java.util.Scanner;
import sun.awt.FcFontManager; import sun.awt.FcFontManager;
import sun.awt.FontConfiguration; import sun.awt.FontConfiguration;
import sun.awt.FontDescriptor; import sun.awt.FontDescriptor;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.font.CompositeFontDescriptor;
import sun.font.FontConfigManager.FontConfigInfo;
import sun.font.FontConfigManager.FcCompFont; import sun.font.FontConfigManager.FcCompFont;
import sun.font.FontConfigManager.FontConfigFont; import sun.font.FontConfigManager.FontConfigFont;
import sun.font.FontConfigManager.FontConfigInfo;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
public class FcFontConfiguration extends FontConfiguration { public class FcFontConfiguration extends FontConfiguration {
/** Version of the cache file format understood by this code. /** Version of the cache file format understood by this code.
@ -178,7 +179,7 @@ public class FcFontConfiguration extends FontConfiguration {
String[] componentFaceNames = cfi[idx].getComponentFaceNames(); String[] componentFaceNames = cfi[idx].getComponentFaceNames();
FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length]; FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length];
for (int i = 0; i < componentFaceNames.length; i++) { for (int i = 0; i < componentFaceNames.length; i++) {
ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.ISO_8859_1.newEncoder(), new int[0]); ret[i] = new FontDescriptor(componentFaceNames[i], ISO_8859_1.newEncoder(), new int[0]);
} }
return ret; return ret;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,10 +32,10 @@ import java.awt.font.FontRenderContext;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.Locale; import java.util.Locale;
import static java.nio.charset.StandardCharsets.UTF_8;
/* /*
* Ideally there would be no native fonts used, and this class would be * Ideally there would be no native fonts used, and this class would be
* unneeded and removed. Presently it is still needed until such time * unneeded and removed. Presently it is still needed until such time
@ -213,23 +213,11 @@ public class NativeFont extends PhysicalFont {
pos = sb.indexOf("-0-", pos); pos = sb.indexOf("-0-", pos);
}; };
String xlfd = sb.toString(); String xlfd = sb.toString();
byte[] bytes = null; return haveBitmapFonts(xlfd.getBytes(UTF_8));
try {
bytes = xlfd.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
bytes = xlfd.getBytes();
}
return haveBitmapFonts(bytes);
} }
public static boolean fontExists(String xlfd) { public static boolean fontExists(String xlfd) {
byte[] bytes = null; return fontExists(xlfd.getBytes(UTF_8));
try {
bytes = xlfd.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
bytes = xlfd.getBytes();
}
return fontExists(bytes);
} }
private static native boolean haveBitmapFonts(byte[] xlfd); private static native boolean haveBitmapFonts(byte[] xlfd);
@ -380,13 +368,7 @@ public class NativeFont extends PhysicalFont {
} }
String xlfd = sb.toString(); String xlfd = sb.toString();
byte[] bytes = null; return xlfd.getBytes(UTF_8);
try {
bytes = xlfd.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
bytes = xlfd.getBytes();
}
return bytes;
} }
public String toString() { public String toString() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +22,13 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package sun.print; package sun.print;
import java.util.Objects;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Objects;
import static java.nio.charset.StandardCharsets.UTF_8;
public class AttributeClass { public class AttributeClass {
private String myName; private String myName;
@ -187,10 +190,7 @@ public class AttributeClass {
byte[] strBytes = new byte[valLength]; byte[] strBytes = new byte[valLength];
bufStream.read(strBytes, 0, valLength); bufStream.read(strBytes, 0, valLength);
try { strVal = new String(strBytes, UTF_8);
strVal = new String(strBytes, "UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
}
} }
return strVal; return strVal;
} }
@ -219,10 +219,7 @@ public class AttributeClass {
int valLength = bufStream.read(); int valLength = bufStream.read();
byte[] bufBytes = new byte[valLength]; byte[] bufBytes = new byte[valLength];
bufStream.read(bufBytes, 0, valLength); bufStream.read(bufBytes, 0, valLength);
try { valueArray[i] = new String(bufBytes, UTF_8);
valueArray[i] = new String(bufBytes, "UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
}
} }
return valueArray; return valueArray;
} }

View File

@ -27,42 +27,82 @@ package sun.print;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import javax.print.attribute.*; import java.io.BufferedReader;
import javax.print.attribute.standard.*; import java.io.ByteArrayOutputStream;
import javax.print.DocFlavor; import java.io.DataInputStream;
import javax.print.DocPrintJob; import java.io.File;
import javax.print.PrintService; import java.io.InputStream;
import javax.print.ServiceUIFactory; import java.io.InputStreamReader;
import java.util.ArrayList; import java.io.OutputStream;
import java.util.HashMap; import java.io.OutputStreamWriter;
import java.util.Locale; import java.net.HttpURLConnection;
import java.util.Date;
import java.util.Arrays;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.print.event.PrintServiceAttributeListener;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.HttpURLConnection; import java.util.ArrayList;
import java.io.File; import java.util.Arrays;
import java.io.InputStream; import java.util.HashMap;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.DataInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.ServiceUIFactory;
import javax.print.attribute.Attribute;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.AttributeSetUtilities;
import javax.print.attribute.EnumSyntax;
import javax.print.attribute.HashAttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.PrintRequestAttribute;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Chromaticity;
import javax.print.attribute.standard.ColorSupported;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.CopiesSupported;
import javax.print.attribute.standard.Destination;
import javax.print.attribute.standard.DialogOwner;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.print.attribute.standard.Fidelity;
import javax.print.attribute.standard.Finishings;
import javax.print.attribute.standard.JobName;
import javax.print.attribute.standard.JobSheets;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import javax.print.attribute.standard.MediaTray;
import javax.print.attribute.standard.NumberUp;
import javax.print.attribute.standard.OrientationRequested;
import javax.print.attribute.standard.PDLOverrideSupported;
import javax.print.attribute.standard.PageRanges;
import javax.print.attribute.standard.PagesPerMinute;
import javax.print.attribute.standard.PagesPerMinuteColor;
import javax.print.attribute.standard.PrinterInfo;
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
import javax.print.attribute.standard.PrinterLocation;
import javax.print.attribute.standard.PrinterMakeAndModel;
import javax.print.attribute.standard.PrinterMessageFromOperator;
import javax.print.attribute.standard.PrinterMoreInfo;
import javax.print.attribute.standard.PrinterMoreInfoManufacturer;
import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.standard.PrinterResolution;
import javax.print.attribute.standard.PrinterState;
import javax.print.attribute.standard.PrinterStateReasons;
import javax.print.attribute.standard.PrinterURI;
import javax.print.attribute.standard.QueuedJobCount;
import javax.print.attribute.standard.RequestingUserName;
import javax.print.attribute.standard.SheetCollate;
import javax.print.attribute.standard.Sides;
import javax.print.event.PrintServiceAttributeListener;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
public class IPPPrintService implements PrintService, SunPrinterJobService { public class IPPPrintService implements PrintService, SunPrinterJobService {
@ -325,11 +365,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
if ((name == null) || (url == null)){ if ((name == null) || (url == null)){
throw new IllegalArgumentException("null uri or printer name"); throw new IllegalArgumentException("null uri or printer name");
} }
try { printer = java.net.URLDecoder.decode(name, UTF_8);
printer = java.net.URLDecoder.decode(name, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
printer = name;
}
supportedDocFlavors = null; supportedDocFlavors = null;
supportedCats = null; supportedCats = null;
mediaSizeNames = null; mediaSizeNames = null;
@ -359,11 +395,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
if ((name == null) || (uriStr == null)){ if ((name == null) || (uriStr == null)){
throw new IllegalArgumentException("null uri or printer name"); throw new IllegalArgumentException("null uri or printer name");
} }
try { printer = java.net.URLDecoder.decode(name, UTF_8);
printer = java.net.URLDecoder.decode(name, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
printer = name;
}
supportedDocFlavors = null; supportedDocFlavors = null;
supportedCats = null; supportedCats = null;
mediaSizeNames = null; mediaSizeNames = null;
@ -1735,9 +1767,8 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
InputStream is = urlConnection.getInputStream(); InputStream is = urlConnection.getInputStream();
if (is != null) { if (is != null) {
BufferedReader d = BufferedReader d = new BufferedReader(
new BufferedReader(new InputStreamReader(is, new InputStreamReader(is, ISO_8859_1));
Charset.forName("ISO-8859-1")));
String lineStr; String lineStr;
while ((lineStr = d.readLine()) != null) { while ((lineStr = d.readLine()) != null) {
if (lineStr.startsWith("*cupsFilter:")) { if (lineStr.startsWith("*cupsFilter:")) {
@ -1829,13 +1860,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
public static boolean writeIPPRequest(OutputStream os, public static boolean writeIPPRequest(OutputStream os,
String operCode, String operCode,
AttributeClass[] attCl) { AttributeClass[] attCl) {
OutputStreamWriter osw; OutputStreamWriter osw = new OutputStreamWriter(os, UTF_8);
try {
osw = new OutputStreamWriter(os, "UTF-8");
} catch (java.io.UnsupportedEncodingException exc) {
debug_println(debugPrefix+"writeIPPRequest, UTF-8 not supported? Exception: "+exc);
return false;
}
debug_println(debugPrefix+"writeIPPRequest, op code= "+operCode); debug_println(debugPrefix+"writeIPPRequest, op code= "+operCode);
char[] opCode = new char[2]; char[] opCode = new char[2];
opCode[0] = (char)Byte.parseByte(operCode.substring(0,2), 16); opCode[0] = (char)Byte.parseByte(operCode.substring(0,2), 16);

View File

@ -25,19 +25,15 @@
package sun.awt.windows; package sun.awt.windows;
import java.awt.Image;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Transparency; import java.awt.Transparency;
import java.awt.color.ColorSpace; import java.awt.color.ColorSpace;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorTable; import java.awt.datatransfer.FlavorTable;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ColorModel; import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel; import java.awt.image.ComponentColorModel;
@ -48,18 +44,16 @@ import java.awt.image.DirectColorModel;
import java.awt.image.ImageObserver; import java.awt.image.ImageObserver;
import java.awt.image.Raster; import java.awt.image.Raster;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.File;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -69,13 +63,11 @@ import java.util.SortedMap;
import sun.awt.Mutex; import sun.awt.Mutex;
import sun.awt.datatransfer.DataTransferer; import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler; import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
import sun.awt.image.ImageRepresentation; import sun.awt.image.ImageRepresentation;
import sun.awt.image.ToolkitImage; import sun.awt.image.ToolkitImage;
import java.util.ArrayList; import static java.nio.charset.StandardCharsets.UTF_16LE;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.ByteArrayOutputStream;
/** /**
* Platform-specific support for the data transfer subsystem. * Platform-specific support for the data transfer subsystem.
@ -249,7 +241,7 @@ final class WDataTransferer extends DataTransferer {
if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) { if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed"); throw new IOException("data translation failed");
} }
String st = new String(bytes, 0, bytes.length, "UTF-16LE"); String st = new String(bytes, 0, bytes.length, UTF_16LE);
String[] filenames = st.split("\0"); String[] filenames = st.split("\0");
if( 0 == filenames.length ){ if( 0 == filenames.length ){
return null; return null;
@ -275,7 +267,7 @@ final class WDataTransferer extends DataTransferer {
{ {
try { try {
charset = new String((byte[])localeTransferable. charset = new String((byte[])localeTransferable.
getTransferData(javaTextEncodingFlavor), "UTF-8"); getTransferData(javaTextEncodingFlavor), UTF_8);
} catch (UnsupportedFlavorException cannotHappen) { } catch (UnsupportedFlavorException cannotHappen) {
} }
} }
@ -548,8 +540,6 @@ enum EHTMLReadMode {
* on encode: static convertToHTMLFormat is responsible for HTML clipboard header creation * on encode: static convertToHTMLFormat is responsible for HTML clipboard header creation
*/ */
class HTMLCodec extends InputStream { class HTMLCodec extends InputStream {
//static section
public static final String ENCODING = "UTF-8";
public static final String VERSION = "Version:"; public static final String VERSION = "Version:";
public static final String START_HTML = "StartHTML:"; public static final String START_HTML = "StartHTML:";
@ -671,13 +661,8 @@ class HTMLCodec extends InputStream {
//HTML //HTML
header.append(htmlPrefix); header.append(htmlPrefix);
byte[] headerBytes = null, trailerBytes = null; byte[] headerBytes = header.toString().getBytes(UTF_8);
byte[] trailerBytes = htmlSuffix.getBytes(UTF_8);
try {
headerBytes = header.toString().getBytes(ENCODING);
trailerBytes = htmlSuffix.getBytes(ENCODING);
} catch (UnsupportedEncodingException cannotHappen) {
}
byte[] retval = new byte[headerBytes.length + bytes.length + byte[] retval = new byte[headerBytes.length + bytes.length +
trailerBytes.length]; trailerBytes.length];
@ -786,7 +771,7 @@ class HTMLCodec extends InputStream {
BufferedReader bufferedReader = new BufferedReader( BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader( new InputStreamReader(
bufferedStream, bufferedStream,
ENCODING UTF_8
), ),
CHAR_BUFFER_LEN CHAR_BUFFER_LEN
); );