The Java File class methods getCanonicalFile and getCanonicalPath call a native ILE function that is dependent on the current job CCSID.
This limits the range of Unicode characters that can be supported.
Java is a Unicode language and the IFS file system supports Unicode path names.
The canonicalize method needs to deal with the IFS file path using Unicode characters and not convert the path to a single byte or double byte CCSID characters.
Refer to PMR 29430,756
Use Case: Scenario: The current folder contains files which have Japanese and Greek characters.
File folder = new File ( "." ) ;
File[] fileArray = folder.listFiles () ;
File file = fileArray[0].
The file.getName() method will contain Japanese and Greek Unicode characters.
File file = fileArray[i].getCanonicalFile () ;
The file.getName() method will contain some Unicode Substitute/Replacement characters as the native CCSID conversion has lost some characters during code page conversion.
============================================
import java.io.* ;
import java.util.Map ;
import java.util.Enumeration ;
public class Test
{
private final static char[] MAP = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' } ;
public static void main ( String[] args ) throws Exception
{
traceEnv () ;
traceSystemProperties () ;
traceFiles () ;
}
private final static void traceFiles () throws IOException
{
File folder = new File ( "." ) ;
File[] fileArray = folder.listFiles () ;
FileOutputStream outputStream = new FileOutputStream ( "OUTPUT.TXT" ) ;
for ( int i=0; i < fileArray.length; i++ )
{
/*
File from folder
*/
if ( fileArray[i].getName ().endsWith ( ".png" ) )
{
traceFile ( outputStream, fileArray[i] ) ;
traceFile ( outputStream, fileArray[i].getCanonicalFile () ) ;
}
}
outputStream.close () ;
}
private final static void traceFile ( FileOutputStream outputStream, File file ) throws IOException
{
try
{
String name = file.getName () ;
write ( outputStream, "" ) ;
write ( outputStream, "[" + name + "] [" + encode ( name.toCharArray () ) + "]" ) ;
write ( outputStream, " exists " + file.exists () ) ;
write ( outputStream, " length " + file.length () ) ;
byte[] content = readFile ( file ) ;
write ( outputStream, " bytes " + content.length ) ;
}
catch ( Exception e )
{
write ( outputStream, " bytes " + e.getMessage () ) ;
}
}
private final static void traceEnv () throws IOException
{
FileOutputStream outputStream = new FileOutputStream ( "ENV.TXT" ) ;
Map<String,String> map = System.getenv () ;
for ( String name : map.keySet () )
{
String value = System.getenv ( name ) ;
write ( outputStream, "[" + name + "] [" + value + "]" ) ;
}
outputStream.close () ;
}
private final static void traceSystemProperties () throws IOException
{
FileOutputStream outputStream = new FileOutputStream ( "SYSTEM.TXT" ) ;
Enumeration enumeration = System.getProperties().propertyNames () ;
while ( enumeration.hasMoreElements () )
{
String name = (String)enumeration.nextElement () ;
String value = System.getProperty ( name ) ;
write ( outputStream, "[" + name + "] [" + value + "]" ) ;
}
outputStream.close () ;
}
private final static void write ( OutputStream outputStream, String line ) throws IOException
{
outputStream.write ( line.getBytes ( "UTF-8" ) ) ;
outputStream.write ( "\r\n".getBytes ( "UTF-8" ) ) ;
}
private final static String encode ( char[] c )
{
StringBuffer buffer = new StringBuffer ( 64 ) ;
for ( int i=0; i < c.length; i++ )
{
buffer.append ( encode ( c[i] ) ) ;
}
return new String ( buffer ) ;
}
private final static String encode ( char c )
{
int index1 = (c & 0xF000) >>> 12 ;
int index2 = (c & 0x0F00) >>> 8 ;
int index3 = (c & 0x00F0) >>> 4 ;
int index4 = (c & 0x000F) ;
return "\\u" + MAP [ index1 ] + MAP [ index2 ] + MAP [ index3 ] + MAP [ index4 ] ;
}
private final static byte[] readFile ( File file ) throws IOException
{
int length = (int)file.length () ;
byte[] content = new byte[length] ;
FileInputStream inputStream = new FileInputStream ( file ) ;
inputStream.read ( content ) ;
inputStream.close () ;
return content ;
}
}
jdk7, jdk7.1, jdk80 on i 7.2 and above releases will include the enhancement.
For IBM i 7.3, it is included in PTF group SF99725 level 4 (released). We will update with PTF information for IBM i 7.2 at a future time.
Creating a new RFE based on Community RFE #91328 in product IBM i.