Source:
<code>@Override public void run() { try { Integer exitStatus = controller._exitStatus(workspace); long lastLocation = 0; FilePath lastLocationFile = controller.getLastLocationFile(workspace); if (lastLocationFile.exists()) { lastLocation = Long.parseLong(lastLocationFile.readToString()); } FilePath logFile = controller.getLogFile(workspace); long len = logFile.length(); if (len > lastLocation) { assert !logFile.isRemote(); try (FileChannel ch = FileChannel.open(Paths.get(logFile.getRemote()), StandardOpenOption.READ)) { InputStream locallyEncodedStream = Channels.newInputStream(ch.position(lastLocation)); InputStream utf8EncodedStream; <START> Charset nativeEncoding = Charset.defaultCharset(); <END> if (nativeEncoding.equals(StandardCharsets.UTF_8)) { utf8EncodedStream = locallyEncodedStream; } else { utf8EncodedStream = new ReaderInputStream(new InputStreamReader(locallyEncodedStream, nativeEncoding), StandardCharsets.UTF_8); } CountingInputStream cis = new CountingInputStream(utf8EncodedStream); handler.output(cis); lastLocationFile.write(Long.toString(lastLocation + cis.getByteCount()), null); } } if (exitStatus != null) { byte[] output; if (controller.getOutputFile(workspace).exists()) { output = controller._getOutput(workspace); } else { output = null; } handler.exited(exitStatus, output); controller.cleanup(workspace); } else { watchService().schedule(this, 100, TimeUnit.MILLISECONDS); } } catch (Exception x) { LOGGER.log(Level.WARNING, "giving up on watching " + controller.controlDir, x); } }</code><technical_language>I assume this is agent's default character set. If ... For reasons (e.g. [JENKINS-13091](<LINK_0> in a situation agent run systems default encoding, i.e. -Dfile.encoding= jvm parameter changing else. system default encoding a good default. However, set encoding explicitly encoding of shell output (IBM1047 z/OS) necessarily match encoding set -Dfile.encoding</technical_language>

Target:
@Override public void run() { try { Integer exitStatus = controller.exitStatus(workspace, listener); long lastLocation = 0; FilePath lastLocationFile = controller.getLastLocationFile(workspace); if (lastLocationFile.exists()) { lastLocation = Long.parseLong(lastLocationFile.readToString()); } FilePath logFile = controller.getLogFile(workspace); long len = logFile.length(); if (len > lastLocation) { assert !logFile.isRemote(); try (FileChannel ch = FileChannel.open(Paths.get(logFile.getRemote()), StandardOpenOption.READ)) { InputStream locallyEncodedStream = Channels.newInputStream(ch.position(lastLocation)); InputStream utf8EncodedStream = cs == null ? locallyEncodedStream : new ReaderInputStream(new InputStreamReader(locallyEncodedStream, cs), StandardCharsets.UTF_8); CountingInputStream cis = new CountingInputStream(utf8EncodedStream); handler.output(cis); lastLocationFile.write(Long.toString(lastLocation + cis.getByteCount()), null); } } if (exitStatus != null) { byte[] output; if (controller.getOutputFile(workspace).exists()) { output = controller.getOutput(workspace); } else { output = null; } handler.exited(exitStatus, output); controller.cleanup(workspace); } else { watchService().schedule(this, 100, TimeUnit.MILLISECONDS); } } catch (Exception x) { LOGGER.log(Level.WARNING, "giving up on watching " + controller.controlDir, x); } }