Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -25,8 +25,12 @@

package com.apple.laf;

import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.Icon;
@@ -111,11 +115,7 @@ static class FileInfo {
FileInfo(final File file){
isDirectory = file.isDirectory();
absolutePath = file.getAbsolutePath();
try {
pathBytes = absolutePath.getBytes("UTF-8");
} catch (final UnsupportedEncodingException e) {
pathBytes = new byte[0];
}
pathBytes = absolutePath.getBytes(StandardCharsets.UTF_8);
}
}

@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,20 +25,26 @@

package sun.lwawt.macosx;

import java.awt.*;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.*;
import java.util.regex.*;
import java.awt.datatransfer.*;
import java.nio.charset.StandardCharsets;
import sun.awt.datatransfer.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;

public class CDataTransferer extends DataTransferer {
private static final Map<String, Long> predefinedClipboardNameMap;
@@ -160,7 +165,9 @@ public Object translateBytes(byte[] bytes, DataFlavor flavor,
// class by base method
format = CF_STRING;
} else if (format == CF_STRING) {
bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8");
String src = new String(bytes, StandardCharsets.UTF_8);
String nfc = Normalizer.normalize(src, Form.NFC);
bytes = nfc.getBytes(StandardCharsets.UTF_8);
}

return super.translateBytes(bytes, flavor, format, transferable);
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,15 @@

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 java.nio.charset.StandardCharsets;

import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
import com.sun.imageio.plugins.common.I18N;
import javax.imageio.metadata.IIOMetadataNode;

import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.ImageUtil;
import org.w3c.dom.Node;

public class BMPMetadata extends IIOMetadata implements BMPConstants {
public static final String nativeMetadataFormatName =
@@ -114,11 +110,7 @@ public Node getAsTree(String formatName) {
}

private String toISO8859(byte[] data) {
try {
return new String(data, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "";
}
return new String(data, StandardCharsets.ISO_8859_1);
}

private Node getNativeTree() {
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,16 +25,14 @@

package com.sun.imageio.plugins.gif;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;

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.IIOMetadataNode;

import org.w3c.dom.Node;

public class GIFImageMetadata extends GIFMetadata {
@@ -132,11 +130,7 @@ public Node getAsTree(String formatName) {
}

private String toISO8859(byte[] data) {
try {
return new String(data, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "";
}
return new String(data, StandardCharsets.ISO_8859_1);
}

private Node getNativeTree() {
@@ -384,12 +378,7 @@ public IIOMetadataNode getStandardTextNode() {

while (commentIter.hasNext()) {
byte[] comment = commentIter.next();
String s = null;
try {
s = new String(comment, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Encoding ISO-8859-1 unknown!");
}
String s = new String(comment, StandardCharsets.ISO_8859_1);

node = new IIOMetadataNode("TextEntry");
node.setAttribute("value", s);
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,17 +25,14 @@

package com.sun.imageio.plugins.gif;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
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.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;

import org.w3c.dom.Node;

class GIFWritableImageMetadata extends GIFImageMetadata {
@@ -95,11 +92,7 @@ public void reset() {
}

private byte[] fromISO8859(String data) {
try {
return data.getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
return "".getBytes();
}
return data.getBytes(StandardCharsets.ISO_8859_1);
}

protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,12 +25,12 @@

package com.sun.imageio.plugins.jpeg;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.metadata.IIOInvalidTreeException;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.w3c.dom.Node;

@@ -45,7 +45,6 @@
* byte array, again assuming the default local encoding.
*/
class COMMarkerSegment extends MarkerSegment {
private static final String ENCODING = "ISO-8859-1";

/**
* Constructs a marker segment from the given buffer, which contains
@@ -96,10 +95,7 @@ class COMMarkerSegment extends MarkerSegment {
* consulted directly.
*/
String getComment() {
try {
return new String (data, ENCODING);
} catch (UnsupportedEncodingException e) {} // Won't happen
return null;
return new String(data, StandardCharsets.ISO_8859_1);
}

/**
@@ -25,40 +25,40 @@

package com.sun.imageio.plugins.jpeg;

import javax.imageio.IIOException;
import javax.imageio.IIOImage;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
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.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.image.BufferedImage;
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.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.imageio.IIOException;
import javax.imageio.IIOImage;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.event.IIOReadProgressListener;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;

/**
* A JFIF (JPEG File Interchange Format) APP0 (Application-Specific)
@@ -1353,7 +1353,7 @@ static void writeICC(ICC_Profile profile, ImageOutputStream ios)
ios.write(0xff);
ios.write(JPEG.APP2);
MarkerSegment.write2bytes(ios, segLength);
byte [] id = ID.getBytes("US-ASCII");
byte[] id = ID.getBytes(StandardCharsets.US_ASCII);
ios.write(id);
ios.write(0); // Null-terminate the string
ios.write(chunkNum++);