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
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -27,7 +27,6 @@

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;
@@ -38,6 +37,8 @@

import com.apple.laf.AquaUtils.RecyclableSingleton;

import static java.nio.charset.StandardCharsets.UTF_8;

@SuppressWarnings("serial") // JDK implementation class
class AquaFileView extends FileView {
private static final boolean DEBUG = false;
@@ -115,7 +116,7 @@ protected static String getPathToSharedJDKBundle() {
FileInfo(final File file){
isDirectory = file.isDirectory();
absolutePath = file.getAbsolutePath();
pathBytes = absolutePath.getBytes(StandardCharsets.UTF_8);
pathBytes = absolutePath.getBytes(UTF_8);
}
}

@@ -33,7 +33,6 @@
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.ArrayList;
@@ -46,6 +45,8 @@
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;

import static java.nio.charset.StandardCharsets.UTF_8;

public class CDataTransferer extends DataTransferer {
private static final Map<String, Long> predefinedClipboardNameMap;
private static final Map<Long, String> predefinedClipboardFormatMap;
@@ -138,7 +139,7 @@ public Object translateBytes(byte[] bytes, DataFlavor flavor,
String charset = Charset.defaultCharset().name();
if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
try {
charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), StandardCharsets.UTF_8);
charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), UTF_8);
} catch (UnsupportedFlavorException cannotHappen) {
}
}
@@ -165,9 +166,8 @@ public Object translateBytes(byte[] bytes, DataFlavor flavor,
// class by base method
format = CF_STRING;
} else if (format == CF_STRING) {
String src = new String(bytes, StandardCharsets.UTF_8);
String nfc = Normalizer.normalize(src, Form.NFC);
bytes = nfc.getBytes(StandardCharsets.UTF_8);
String src = new String(bytes, UTF_8);
bytes = Normalizer.normalize(src, Form.NFC).getBytes(UTF_8);
}

return super.translateBytes(bytes, flavor, format, transferable);
@@ -25,8 +25,6 @@

package com.sun.imageio.plugins.bmp;

import java.nio.charset.StandardCharsets;

import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;
@@ -35,6 +33,8 @@
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 static final String nativeMetadataFormatName =
"javax_imageio_bmp_1.0";
@@ -110,7 +110,7 @@ public Node getAsTree(String formatName) {
}

private String toISO8859(byte[] data) {
return new String(data, StandardCharsets.ISO_8859_1);
return new String(data, ISO_8859_1);
}

private Node getNativeTree() {
@@ -25,7 +25,6 @@

package com.sun.imageio.plugins.gif;

import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;

@@ -35,6 +34,8 @@

import org.w3c.dom.Node;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

public class GIFImageMetadata extends GIFMetadata {

// package scope
@@ -130,7 +131,7 @@ public Node getAsTree(String formatName) {
}

private String toISO8859(byte[] data) {
return new String(data, StandardCharsets.ISO_8859_1);
return new String(data, ISO_8859_1);
}

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

while (commentIter.hasNext()) {
byte[] comment = commentIter.next();
String s = new String(comment, StandardCharsets.ISO_8859_1);
String s = new String(comment, ISO_8859_1);

node = new IIOMetadataNode("TextEntry");
node.setAttribute("value", s);
@@ -26,7 +26,6 @@
package com.sun.imageio.plugins.gif;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

import javax.imageio.metadata.IIOInvalidTreeException;
@@ -35,6 +34,8 @@

import org.w3c.dom.Node;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

class GIFWritableImageMetadata extends GIFImageMetadata {

// package scope
@@ -92,7 +93,7 @@ public void reset() {
}

private byte[] fromISO8859(String data) {
return data.getBytes(StandardCharsets.ISO_8859_1);
return data.getBytes(ISO_8859_1);
}

protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {
@@ -26,14 +26,15 @@
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 org.w3c.dom.Node;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

/**
* 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
@@ -95,7 +96,7 @@
* consulted directly.
*/
String getComment() {
return new String(data, StandardCharsets.ISO_8859_1);
return new String(data, ISO_8859_1);
}

/**
@@ -40,7 +40,6 @@
import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -60,6 +59,8 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import static java.nio.charset.StandardCharsets.US_ASCII;

/**
* A JFIF (JPEG File Interchange Format) APP0 (Application-Specific)
* marker segment. Inner classes are included for JFXX extension
@@ -1353,7 +1354,7 @@ static void writeICC(ICC_Profile profile, ImageOutputStream ios)
ios.write(0xff);
ios.write(JPEG.APP2);
MarkerSegment.write2bytes(ios, segLength);
byte[] id = ID.getBytes(StandardCharsets.US_ASCII);
byte[] id = ID.getBytes(US_ASCII);
ios.write(id);
ios.write(0); // Null-terminate the string
ios.write(chunkNum++);
@@ -42,7 +42,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@@ -63,6 +62,9 @@
import com.sun.imageio.plugins.common.SubImageInputStream;
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> {

boolean firstTime = true;
@@ -489,9 +491,9 @@ private void parse_iTXt_chunk(int chunkLength) throws IOException {
stream.readFully(b);

if (compressionFlag == 1) { // Decompress the text
text = new String(inflate(b), StandardCharsets.UTF_8);
text = new String(inflate(b), UTF_8);
} else {
text = new String(b, StandardCharsets.UTF_8);
text = new String(b, UTF_8);
}
metadata.iTXt_text.add(text);

@@ -592,7 +594,7 @@ private void parse_tEXt_chunk(int chunkLength) throws IOException {

byte[] b = new byte[textLength];
stream.readFully(b);
metadata.tEXt_text.add(new String(b, StandardCharsets.ISO_8859_1));
metadata.tEXt_text.add(new String(b, ISO_8859_1));

// Check if the text chunk contains image creation time
if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {
@@ -693,8 +695,7 @@ private void parse_zTXt_chunk(int chunkLength) throws IOException {

byte[] b = new byte[textLength];
stream.readFully(b);
metadata.zTXt_text.add(new String(inflate(b),
StandardCharsets.ISO_8859_1));
metadata.zTXt_text.add(new String(inflate(b), ISO_8859_1));

// Check if the text chunk contains image creation time
if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {
@@ -33,7 +33,6 @@
import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Locale;
import java.util.zip.Deflater;
@@ -49,6 +48,9 @@
import javax.imageio.stream.ImageOutputStream;
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 {

private static final int[] crcTable = new int[256];
@@ -803,16 +805,14 @@ private void write_iTXt() throws IOException {
cs.writeBytes(languageIter.next());
cs.writeByte(0);


cs.write(translatedKeywordIter.next()
.getBytes(StandardCharsets.UTF_8));
cs.write(translatedKeywordIter.next().getBytes(UTF_8));
cs.writeByte(0);

String text = textIter.next();
if (compressed) {
cs.write(deflate(text.getBytes(StandardCharsets.UTF_8)));
cs.write(deflate(text.getBytes(UTF_8)));
} else {
cs.write(text.getBytes(StandardCharsets.UTF_8));
cs.write(text.getBytes(UTF_8));
}
cs.finish();
}
@@ -836,7 +836,7 @@ private void write_zTXt() throws IOException {
cs.writeByte(compressionMethod);

String text = textIter.next();
cs.write(deflate(text.getBytes(StandardCharsets.ISO_8859_1)));
cs.write(deflate(text.getBytes(ISO_8859_1)));
cs.finish();
}
}
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -22,24 +22,27 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.sun.imageio.plugins.tiff;

import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

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.TIFFDirectory;
import javax.imageio.plugins.tiff.TIFFField;
import javax.imageio.plugins.tiff.TIFFTag;
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 {
private static final long MAX_SAMPLES_PER_PIXEL = 0xffff;
@@ -283,8 +286,7 @@ private static int readFieldValue(ImageInputStream stream,
if (inString) {
// end of string
String s = new String(bvalues, prevIndex,
index - prevIndex,
StandardCharsets.US_ASCII);
index - prevIndex, US_ASCII);
v.add(s);
inString = false;
}