24 Eylül 2019 Salı

Compress TarArchiveOutputStream Snııfı

constructor
Şöyle yaparız.
FileOutputStream fos = new FileOutputStream("output.tar");
BufferedOutputStream bos = new BufferedOutputStream(fos);
GzipCompressorOutputStream goz = new GzipCompressorOutputStream(bos);
TarArchiveOutputStream tos = new TarArchiveOutputStream(goz);
write metodu
Şöyle yaparız.
FileInputStream source=new FileInputStream(....somefile);
tarArchiveOutputStream; prepared to w writing

byte[] buff = new byte[1024*10]; //10kb buff
int numBytesRead = -1; //number of bytes read


while(( numBytesRead = source.read(buff)) > 0 ) {
  // while source has bytes, read from source and write
  // the same number of bytes to the tar outputstream
  tarArchiveOutputStream.write(buff, 0, numBytesRead);
}

Hiç yorum yok:

Yorum Gönder