Skip to content
Permalink
Browse files

Improved: Use ‘StandardCharsets.UTF_8’

(OFBIZ-11142)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863505 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 20, 2019
1 parent 2c2340d commit fc6f9023d2727016329d0f8b59e859d35a4dc70f
Showing with 110 additions and 93 deletions.
  1. +5 −4 applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
  2. +3 −2 applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java
  3. +2 −1 applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
  4. +2 −1 applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechServices.java
  5. +2 −1 applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java
  6. +2 −1 applications/product/src/main/java/org/apache/ofbiz/shipment/thirdparty/dhl/DhlServices.java
  7. +2 −1 applications/product/src/main/java/org/apache/ofbiz/shipment/thirdparty/fedex/FedexServices.java
  8. +13 −13 applications/product/src/main/java/org/apache/ofbiz/shipment/thirdparty/ups/UpsServices.java
  9. +4 −3 applications/product/src/main/java/org/apache/ofbiz/shipment/thirdparty/usps/UspsServices.java
  10. +12 −12 framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java
  11. +4 −4 framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
  12. +8 −7 framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java
  13. +4 −3 framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java
  14. +3 −4 framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java
  15. +2 −1 framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java
  16. +6 −10 framework/base/src/main/java/org/apache/ofbiz/base/util/UtilIO.java
  17. +2 −1 framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
  18. +5 −4 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilIOTests.java
  19. +3 −2 framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
  20. +3 −2 framework/datafile/src/main/java/org/apache/ofbiz/datafile/DataFile.java
  21. +3 −2 framework/datafile/src/main/java/org/apache/ofbiz/datafile/DataFile2EntityXml.java
  22. +5 −4 framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java
  23. +4 −3 framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
  24. +2 −1 framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java
  25. +2 −1 framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
  26. +4 −3 framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java
  27. +3 −2 framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java
@@ -30,6 +30,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
@@ -987,7 +988,7 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
if (!file.isAbsolute()) {
throw new GeneralException("File (" + objectInfo + ") is not absolute");
}
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), UtilIO.getUtf8())) {
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
UtilIO.copy(in, out);
}
} else if ("OFBIZ_FILE".equals(dataResourceTypeId) && UtilValidate.isNotEmpty(objectInfo)) {
@@ -997,7 +998,7 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
sep = "/";
}
File file = FileUtil.getFile(prefix + sep + objectInfo);
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), UtilIO.getUtf8())) {
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
UtilIO.copy(in, out);
}
} else if ("CONTEXT_FILE".equals(dataResourceTypeId) && UtilValidate.isNotEmpty(objectInfo)) {
@@ -1007,7 +1008,7 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
sep = "/";
}
File file = FileUtil.getFile(prefix + sep + objectInfo);
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), UtilIO.getUtf8())) {
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
if (Debug.infoOn()) {
String enc = in.getEncoding();
Debug.logInfo("in serveImage, encoding:" + enc, module);
@@ -1064,7 +1065,7 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
throw new GeneralException("Unsupported TEXT type; cannot stream");
}

byte[] bytes = text.getBytes(UtilIO.getUtf8());
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
return UtilMisc.toMap("stream", new ByteArrayInputStream(bytes), "length", (long) bytes.length);

// object (binary) data
@@ -27,6 +27,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashMap;
@@ -244,7 +245,7 @@
// write the data to the file
if (UtilValidate.isNotEmpty(textData)) {
try (
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), UtilIO.getUtf8());
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
) {
out.write(textData);
} catch (IOException e) {
@@ -433,7 +434,7 @@
// write the data to the file
if (UtilValidate.isNotEmpty(textData)) {
try (
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file),UtilIO.getUtf8());
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file),StandardCharsets.UTF_8);
) {
out.write(textData);
} catch (IOException e) {
@@ -25,6 +25,7 @@
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -225,7 +226,7 @@ protected Template getTemplate(URL templateUrl) {
Template template = null;
try (
InputStream templateStream = templateUrl.openStream();
InputStreamReader templateReader = new InputStreamReader(templateStream,UtilIO.getUtf8());
InputStreamReader templateReader = new InputStreamReader(templateStream,StandardCharsets.UTF_8);
){
template = new Template(templateUrl.toExternalForm(), templateReader, config);
} catch (IOException e) {
@@ -19,6 +19,7 @@

package org.apache.ofbiz.party.contact;

import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.sql.Timestamp;
import java.util.Date;
@@ -973,7 +974,7 @@
synchronized(ContactMechServices.class) {
while (true) {
Long random = secureRandom.nextLong();
verifyHash = HashCrypt.digestHash("MD5", Long.toString(random).getBytes(UtilIO.getUtf8()));
verifyHash = HashCrypt.digestHash("MD5", Long.toString(random).getBytes(StandardCharsets.UTF_8));
List<GenericValue> emailAddVerifications = null;
try {
emailAddVerifications = EntityQuery.use(delegator).from("EmailAddressVerification").where("verifyHash", verifyHash).queryList();
@@ -23,6 +23,7 @@
import java.io.StringReader;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.LinkedList;
@@ -244,7 +245,7 @@
byte[] wrapper = bytebufferwrapper.array();

// read the bytes into a reader
BufferedReader reader = new BufferedReader(new StringReader(new String(wrapper, UtilIO.getUtf8())));
BufferedReader reader = new BufferedReader(new StringReader(new String(wrapper, StandardCharsets.UTF_8)));
List<Object> errors = new LinkedList<>();
int lines = 0;
String line;
@@ -22,6 +22,7 @@
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedList;
@@ -850,7 +851,7 @@ public static String sendDhlRequest(String xmlString, Delegator delegator, Strin
continue;
sb.append(encodedImageString.charAt(i));
}
byte[] labelBytes = Base64.getMimeDecoder().decode(sb.toString().getBytes(UtilIO.getUtf8()));
byte[] labelBytes = Base64.getMimeDecoder().decode(sb.toString().getBytes(StandardCharsets.UTF_8));

if (labelBytes != null) {
// store in db blob
@@ -23,6 +23,7 @@
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.Base64;
import java.util.HashMap;
@@ -1021,7 +1022,7 @@ public static String sendFedexRequest(String xmlString, Delegator delegator, Str
"fDXShipReplyString", fDXShipReplyString), locale));
}

byte[] labelBytes = Base64.getMimeDecoder().decode(encodedImageString.getBytes(UtilIO.getUtf8()));
byte[] labelBytes = Base64.getMimeDecoder().decode(encodedImageString.getBytes(StandardCharsets.UTF_8));

if (labelBytes != null) {

@@ -635,7 +635,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentConfirmRequest" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(xmlString.toString().getBytes(UtilIO.getUtf8()));
fileOut.write(xmlString.toString().getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -654,7 +654,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentConfirmResponse" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(shipmentConfirmResponseString.getBytes(UtilIO.getUtf8()));
fileOut.write(shipmentConfirmResponseString.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -908,7 +908,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentAcceptRequest" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(xmlString.toString().getBytes(UtilIO.getUtf8()));
fileOut.write(xmlString.toString().getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -927,7 +927,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentAcceptResponse" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(shipmentAcceptResponseString.getBytes(UtilIO.getUtf8()));
fileOut.write(shipmentAcceptResponseString.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -1105,12 +1105,12 @@
}
byte[] labelImageBytes = null;
if (packageLabelGraphicImageString != null) {
labelImageBytes = Base64.getMimeDecoder().decode(packageLabelGraphicImageString.getBytes(UtilIO.getUtf8()));
labelImageBytes = Base64.getMimeDecoder().decode(packageLabelGraphicImageString.getBytes(StandardCharsets.UTF_8));
shipmentPackageRouteSeg.setBytes("labelImage", labelImageBytes);
}
byte[] labelInternationalSignatureGraphicImageBytes = null;
if (packageLabelInternationalSignatureGraphicImageString != null) {
labelInternationalSignatureGraphicImageBytes = Base64.getMimeDecoder().decode(packageLabelInternationalSignatureGraphicImageString.getBytes(UtilIO.getUtf8()));
labelInternationalSignatureGraphicImageBytes = Base64.getMimeDecoder().decode(packageLabelInternationalSignatureGraphicImageString.getBytes(StandardCharsets.UTF_8));
shipmentPackageRouteSeg.set("labelIntlSignImage", labelInternationalSignatureGraphicImageBytes);
}
String packageLabelHTMLImageStringDecoded = Arrays.toString(Base64.getMimeDecoder().decode(packageLabelHTMLImageString.getBytes(StandardCharsets.UTF_8)));
@@ -1138,7 +1138,7 @@
if (packageLabelHTMLImageStringDecoded != null) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentLabelHTMLImage" + shipmentRouteSegment.getString("shipmentId") + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + "_" + shipmentPackageRouteSeg.getString("shipmentPackageSeqId") + ".html";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(packageLabelHTMLImageStringDecoded.getBytes(UtilIO.getUtf8()));
fileOut.write(packageLabelHTMLImageStringDecoded.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS LabelImage HTML file: [[[" + packageLabelHTMLImageStringDecoded + "]]] to file: " + outFileName, module);
@@ -1169,7 +1169,7 @@
shipmentRouteSegment.store();
String outFileName = shipmentUpsSaveCertificationPath + "/HighValueReport" + shipmentRouteSegment.getString("shipmentId") + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".html";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(fileStringDecoded.getBytes(UtilIO.getUtf8()));
fileOut.write(fileStringDecoded.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS High Value Report data: [[[" + fileStringDecoded + "]]] to file: " + outFileName, module);
@@ -1290,7 +1290,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsVoidShipmentRequest" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(xmlString.toString().getBytes(UtilIO.getUtf8()));
fileOut.write(xmlString.toString().getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -1309,7 +1309,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsVoidShipmentResponse" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(voidShipmentResponseString.getBytes(UtilIO.getUtf8()));
fileOut.write(voidShipmentResponseString.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -1486,7 +1486,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsTrackRequest" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(xmlString.toString().getBytes(UtilIO.getUtf8()));
fileOut.write(xmlString.toString().getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -1505,7 +1505,7 @@
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsTrackResponseString" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(trackResponseString.getBytes(UtilIO.getUtf8()));
fileOut.write(trackResponseString.getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -2644,7 +2644,7 @@ public static String sendUpsRequest(String upsService, String xmlString, String
if (shipmentUpsSaveCertificationInfo) {
String outFileName = shipmentUpsSaveCertificationPath + "/UpsShipmentAcceptRequest" + shipmentId + "_" + shipmentRouteSegment.getString("shipmentRouteSegmentId") + ".xml";
try (FileOutputStream fileOut = new FileOutputStream(outFileName)) {
fileOut.write(xmlString.toString().getBytes(UtilIO.getUtf8()));
fileOut.write(xmlString.toString().getBytes(StandardCharsets.UTF_8));
fileOut.flush();
} catch (IOException e) {
Debug.logInfo(e, "Could not save UPS XML file: [[[" + xmlString.toString() + "]]] to file: " + outFileName, module);
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.Base64;
import java.util.Collections;
@@ -1410,7 +1411,7 @@
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"FacilityShipmentUspsDeliveryConfirmationResponseIncompleteElementDeliveryConfirmationLabel", locale));
}
shipmentPackageRouteSeg.setBytes("labelImage", Base64.getMimeDecoder().decode(labelImageString.getBytes(UtilIO.getUtf8())));
shipmentPackageRouteSeg.setBytes("labelImage", Base64.getMimeDecoder().decode(labelImageString.getBytes(StandardCharsets.UTF_8)));
String trackingCode = UtilXml.childElementValue(responseElement, "DeliveryConfirmationNumber");
if (UtilValidate.isEmpty(trackingCode)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -1650,7 +1651,7 @@
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"FacilityShipmentUspsPriorityMailLabelResponseIncompleteElementLabelImage", locale));
}
shipmentPackageRouteSeg.setBytes("labelImage", Base64.getMimeDecoder().decode(labelImageString.getBytes(UtilIO.getUtf8())));
shipmentPackageRouteSeg.setBytes("labelImage", Base64.getMimeDecoder().decode(labelImageString.getBytes(StandardCharsets.UTF_8)));
String trackingCode = UtilXml.childElementValue(responseElement, "BarcodeNumber");
if (UtilValidate.isEmpty(trackingCode)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -1704,7 +1705,7 @@ private static Document sendUspsRequest(String requestType, Document requestDocu
UtilMisc.toMap("errorString", e.getMessage()), locale));
}

String xmlString = new String(os.toByteArray(), UtilIO.getUtf8());
String xmlString = new String(os.toByteArray(), StandardCharsets.UTF_8);

Debug.logInfo("USPS XML request string: " + xmlString, module);

0 comments on commit fc6f902

Please sign in to comment.
You can’t perform that action at this time.