Пример #1
0
 private File writeFile(TarOutputStream tar, FileDTO dto, String tarEntryName)
     throws IOException, FileNotFoundException {
   File file = FileUtils.toFile(dto.getDirectoryPath(), dto.getFilePath());
   TarEntry entry = new TarEntry(tarEntryName);
   entry.setSize(dto.getFileSize());
   tar.putNextEntry(entry);
   FileInputStream fis = new FileInputStream(file);
   try {
     tar.copyEntryContents(fis);
   } finally {
     fis.close();
   }
   tar.closeEntry();
   return file;
 }
Пример #2
0
 private void writeMD5SUM(TarOutputStream tar, FileDTO[] dto, String[] tarEntryNames)
     throws IOException {
   byte[] md5sum = new byte[dto.length * MD5SUM_ENTRY_LEN];
   final TarEntry tarEntry = new TarEntry("MD5SUM");
   tarEntry.setSize(md5sum.length);
   tar.putNextEntry(tarEntry);
   int i = 0;
   for (int j = 0; j < tarEntryNames.length; j++) {
     MD5Utils.toHexChars(dto[j].getFileMd5(), md5sum, i);
     md5sum[i + 32] = ' ';
     md5sum[i + 33] = ' ';
     System.arraycopy(tarEntryNames[j].getBytes("US-ASCII"), 0, md5sum, i + 34, 17);
     md5sum[i + 51] = '\n';
     i += MD5SUM_ENTRY_LEN;
   }
   tar.write(md5sum);
   tar.closeEntry();
 }