Skip to content

Commit

Permalink
Merge pull request apache#3611 from nadment/3610
Browse files Browse the repository at this point in the history
Replaces "UTF-8" strings with StandardCharsets.UTF_8 apache#3610
  • Loading branch information
usbrandon authored Feb 13, 2024
2 parents 9e6165d + 8bcc799 commit 692d108
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -470,7 +471,7 @@ protected URLClassLoader createUrlClassLoader(URL jarFileUrl, ClassLoader classL
JarCache jarCache = JarCache.getInstance();

String parentFolderName =
new File(URLDecoder.decode(jarFileUrl.getFile(), "UTF-8")).getParent();
new File(URLDecoder.decode(jarFileUrl.getFile(), StandardCharsets.UTF_8)).getParent();

File libFolder = new File(parentFolderName + Const.FILE_SEPARATOR + "lib");
if (libFolder.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -338,7 +339,7 @@ private HopURLClassLoader createClassLoader(IPlugin plugin)
URL[] urls = new URL[jarFiles.size()];
for (int i = 0; i < jarFiles.size(); i++) {
File jarFile = new File(jarFiles.get(i));
urls[i] = new URL(URLDecoder.decode(jarFile.toURI().toURL().toString(), "UTF-8"));
urls[i] = new URL(URLDecoder.decode(jarFile.toURI().toURL().toString(), StandardCharsets.UTF_8));
}
ClassLoader classLoader = getClass().getClassLoader();
String[] patterns = parentClassloaderPatternMap.get(plugin);
Expand All @@ -360,7 +361,7 @@ private void addToClassLoader(IPlugin plugin, HopURLClassLoader ucl)

for (String jarFile : plugin.getLibraries()) {
File jarfile = new File(jarFile);
ucl.addURL(new URL(URLDecoder.decode(jarfile.toURI().toURL().toString(), "UTF-8")));
ucl.addURL(new URL(URLDecoder.decode(jarfile.toURI().toURL().toString(), StandardCharsets.UTF_8)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected static URLClassLoader createUrlClassLoader(URL jarFileUrl, ClassLoader
JarCache jarCache = JarCache.getInstance();

String parentFolderName =
new File(URLDecoder.decode(jarFileUrl.getFile(), "UTF-8")).getParent();
new File(URLDecoder.decode(jarFileUrl.getFile(), StandardCharsets.UTF_8)).getParent();

File libFolder = new File(parentFolderName + Const.FILE_SEPARATOR + "lib");
if (libFolder.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.w3c.dom.Node;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -378,7 +379,7 @@ private void sendToHopServer(
this,
PrepareExecutionPipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineMeta.getName(), "UTF-8")
+ URLEncoder.encode(pipelineMeta.getName(), StandardCharsets.UTF_8)
+ "&xml=Y&id="
+ containerId);
WebResult webResult = WebResult.fromXmlString(reply);
Expand Down Expand Up @@ -452,7 +453,7 @@ public void startThreads() throws HopException {
this,
StartExecutionPipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(subject.getName(), "UTF-8")
+ URLEncoder.encode(subject.getName(), StandardCharsets.UTF_8)
+ "&xml=Y&id="
+ containerId);
WebResult webResult = WebResult.fromXmlString(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hop.pipeline.PipelineMeta;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -163,7 +164,7 @@ public static final TopLevelResource serializeResourceExportInterface(
ZipEntry jsonEntry = new ZipEntry("metadata.json");
jsonEntry.setComment("Export of the client metadata");
out.putNextEntry(jsonEntry);
out.write(new SerializableMetadataProvider(metadataProvider).toJson().getBytes("UTF-8"));
out.write(new SerializableMetadataProvider(metadataProvider).toJson().getBytes(StandardCharsets.UTF_8));
out.closeEntry();

String zipURL = fileObject.getName().toString();
Expand Down
31 changes: 16 additions & 15 deletions engine/src/main/java/org/apache/hop/server/HopServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -99,6 +98,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

@HopMetadata(
key = "server",
name = "Hop Server",
Expand Down Expand Up @@ -621,7 +622,7 @@ HttpPost buildSendExportMethod(IVariables variables, String type, String load, I
+ "&"
+ RegisterPackageServlet.PARAMETER_LOAD
+ "="
+ URLEncoder.encode(load, "UTF-8");
+ URLEncoder.encode(load, UTF_8);
}

String urlString = constructUrl(variables, serviceUrl);
Expand Down Expand Up @@ -799,7 +800,7 @@ public String execService(IVariables variables, String service) throws Exception

// Method is defined as package-protected in order to be accessible by unit tests
String getResponseBodyAsString(InputStream is) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, UTF_8));
StringBuilder bodyBuffer = new StringBuilder();
String line;

Expand Down Expand Up @@ -918,7 +919,7 @@ public HopServerPipelineStatus getPipelineStatus(
String query =
GetPipelineStatusServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y&from="
Expand All @@ -938,7 +939,7 @@ public HopServerWorkflowStatus getWorkflowStatus(
variables,
GetWorkflowStatusServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(workflowName, "UTF-8")
+ URLEncoder.encode(workflowName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y&from="
Expand All @@ -954,7 +955,7 @@ public WebResult stopPipeline(IVariables variables, String pipelineName, String
variables,
StopPipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y");
Expand All @@ -968,7 +969,7 @@ public WebResult pauseResumePipeline(
variables,
PausePipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y");
Expand All @@ -982,7 +983,7 @@ public WebResult removePipeline(IVariables variables, String pipelineName, Strin
variables,
RemovePipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y");
Expand All @@ -996,7 +997,7 @@ public WebResult removeWorkflow(IVariables variables, String workflowName, Strin
variables,
RemoveWorkflowServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(workflowName, "UTF-8")
+ URLEncoder.encode(workflowName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y");
Expand All @@ -1010,7 +1011,7 @@ public WebResult stopWorkflow(IVariables variables, String pipelineName, String
variables,
StopWorkflowServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&xml=Y&id="
+ Const.NVL(serverObjectId, ""));
return WebResult.fromXmlString(xml);
Expand All @@ -1023,7 +1024,7 @@ public WebResult startPipeline(IVariables variables, String pipelineName, String
variables,
StartPipelineServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ Const.NVL(serverObjectId, "")
+ "&xml=Y");
Expand All @@ -1037,7 +1038,7 @@ public WebResult startWorkflow(IVariables variables, String workflowName, String
variables,
StartWorkflowServlet.CONTEXT_PATH
+ "/?name="
+ URLEncoder.encode(workflowName, "UTF-8")
+ URLEncoder.encode(workflowName, UTF_8)
+ "&xml=Y&id="
+ Const.NVL(serverObjectId, ""));
return WebResult.fromXmlString(xml);
Expand Down Expand Up @@ -1114,11 +1115,11 @@ public String sniffTransform(
variables,
SniffTransformServlet.CONTEXT_PATH
+ "/?pipeline="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&transform="
+ URLEncoder.encode(transformName, "UTF-8")
+ URLEncoder.encode(transformName, UTF_8)
+ "&copynr="
+ copyNr
+ "&type="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import static java.nio.charset.StandardCharsets.UTF_8;

@HopServerServlet(id = "pipelineImage", name = "Generate a PNG image of a pipeline")
public class GetPipelineImageServlet extends BaseHttpServlet implements IHopServerPlugin {
Expand Down Expand Up @@ -85,7 +86,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
PipelineSvgPainter.generatePipelineSvg(pipeline.getPipelineMeta(), 1.0f, variables);
svgStream = new ByteArrayOutputStream();
try {
svgStream.write(svgXml.getBytes("UTF-8"));
svgStream.write(svgXml.getBytes(UTF_8));
} finally {
svgStream.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Date;
import static java.nio.charset.StandardCharsets.UTF_8;

@HopServerServlet(id = "pipelineStatus", name = "Get the status of a pipeline")
public class GetPipelineStatusServlet extends BaseHttpServlet implements IHopServerPlugin {
Expand Down Expand Up @@ -210,9 +211,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
"<META http-equiv=\"Refresh\" content=\"10;url="
+ convertContextPath(CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "\">");
}
out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
Expand Down Expand Up @@ -298,9 +299,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
"<a target=\"_blank\" href=\""
+ convertContextPath(GetPipelineStatusServlet.CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&xml=y\">"
+ "<img src=\""
+ prefix
Expand All @@ -314,9 +315,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
"<a target=\"_blank\" href=\""
+ convertContextPath(GetPipelineStatusServlet.CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&xml=y\">"
+ BaseMessages.getString(PKG, "PipelineStatusServlet.ShowAsXml")
+ "</a>");
Expand All @@ -337,9 +338,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
"<a target=\"_blank\" href=\""
+ convertContextPath(GetPipelineStatusServlet.CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&json=y\">"
+ "<img src=\""
+ prefix
Expand All @@ -353,9 +354,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
"<a target=\"_blank\" href=\""
+ convertContextPath(GetPipelineStatusServlet.CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&json=y\">"
+ BaseMessages.getString(PKG, "PipelineStatusServlet.ShowAsJson")
+ "</a>");
Expand Down Expand Up @@ -413,16 +414,16 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
" <a href=\""
+ convertContextPath(SniffTransformServlet.CONTEXT_PATH)
+ "?pipeline="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "&lines=50"
+ "&copynr="
+ component.getCopyNr()
+ "&type="
+ SniffTransformServlet.TYPE_OUTPUT
+ "&transform="
+ URLEncoder.encode(component.getName(), "UTF-8")
+ URLEncoder.encode(component.getName(), UTF_8)
+ "\">"
+ Encode.forHtml(transformStatus.getTransformName())
+ "</a>";
Expand Down Expand Up @@ -523,9 +524,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ "src=\""
+ convertContextPath(GetPipelineImageServlet.CONTEXT_PATH)
+ "?name="
+ URLEncoder.encode(pipelineName, "UTF-8")
+ URLEncoder.encode(pipelineName, UTF_8)
+ "&id="
+ URLEncoder.encode(id, "UTF-8")
+ URLEncoder.encode(id, UTF_8)
+ "\" frameborder=\"0\"></iframe>");
;
out.print("</div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

@HopServerServlet(id = "workflowImage", name = "Generate a PNG image of a workflow")
public class GetWorkflowImageServlet extends BaseHttpServlet implements IHopServerPlugin {
Expand Down Expand Up @@ -96,7 +97,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
WorkflowSvgPainter.generateWorkflowSvg(workflow.getWorkflowMeta(), 1.0f, variables);
svgStream = new ByteArrayOutputStream();
try {
svgStream.write(svgXml.getBytes("UTF-8"));
svgStream.write(svgXml.getBytes(StandardCharsets.UTF_8));
} finally {
svgStream.flush();
}
Expand Down
Loading

0 comments on commit 692d108

Please sign in to comment.