Skip to content

Commit

Permalink
Merge pull request ibmruntimes#154 from Danja-Papajani/path-file-1-in…
Browse files Browse the repository at this point in the history
…ter-patch

Port PathFileObject.java from Java 11 z/OS
  • Loading branch information
PUSHKAR KULKARNI authored and GitHub Enterprise committed Aug 22, 2022
2 parents d337ea1 + 4102c3f commit d3f9fff
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2019, 2019 All Rights Reserved
* ===========================================================================
*/

package com.sun.tools.javac.file;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -47,6 +54,7 @@

import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import java.lang.UnsupportedOperationException;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;

Expand Down Expand Up @@ -458,7 +466,30 @@ public URI toUri() {
@Override @DefinedBy(Api.COMPILER)
public InputStream openInputStream() throws IOException {
fileManager.updateLastUsedTime();
return Files.newInputStream(path);
if (System.getProperty("os.name").equals("z/OS")) {
// Files.newInputStream(path) creates a ChannelInputStream
// and this seems to do auto-conversion based on the tagged
// codepage (Enhanced ASCII support) on zOS. This causes
// issue when the '-encoding' option is set on javac command
// To stop this we will create the FileInputStream directly
InputStream is;
try {
// if the encoding is set on the command line then use
// a FileInputStream otherwise use the Files.newInputStream
if (fileManager.getRawEncodingName() != null) {
is = new FileInputStream(path.toFile());
} else {
is = Files.newInputStream(path);
}
} catch (UnsupportedOperationException usoe ) {
// Some Path objects do not support the toFile() operation
// so in this case we will revert to using the original method
is = Files.newInputStream(path);
}
return is;
} else {
return Files.newInputStream(path);
}
}

@Override @DefinedBy(Api.COMPILER)
Expand Down

0 comments on commit d3f9fff

Please sign in to comment.