I am compressing files using the Apache Commons API Compression. Windows 7 works fine, but in Linux (ubuntu 10.10 - UTF8), characters in file names and folder names, such as "º", for example, are replaced by "?".
Is there any parameter I should pass to the API when compact, or when uncompressing tar?
I'am using tar.gz format, following the API examples.
The files I'm trying compress, are created in windows... is there any trouble?
The code:
public class TarGzTest
{
public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException
{
System.out.println("Criando tar.gz da pasta " + directoryPath + " em " + tarGzPath);
FileOutputStream fOut = null;
BufferedOutputStream bOut = null;
GzipCompressorOutputStream gzOut = null;
TarArchiveOutputStream tOut = null;
try
{
fOut = new FileOutputStream(new File(tarGzPath));
bOut = new BufferedOutputStream(fOut);
gzOut = new GzipCompressorOutputStream(bOut);
tOut = new TarArchiveOutputStream(gzOut);
addFileToTarGz(tOut, directoryPath, "");
}
finally
{
tOut.finish();
tOut.close();
gzOut.close();
bOut.close();
fOut.close();
}
System.out.println("Processo concluído.");
}
private static void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException
{
System.out.println("addFileToTarGz()::"+path);
File f = new File(path);
String entryName = base + f.getName();
TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
if(f.isFile())
{
tOut.putArchiveEntry(tarEntry);
IOUtils.copy(new FileInputStream(f), tOut);
tOut.closeArchiveEntry();
}
else
{
File[] children = f.listFiles();
if(children != null)
{
for(File child : children)
{
addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
}
}
}
}
}
(I suppress the main method;)
EDIT (monkeyjluffy) : The changes that I made are to have always the same archive on different platform. Then the hash calculated on it is the same.