12 Şubat 2019 Salı

Compress ZipArchiveOutputStream Sınıfı

Giriş
Şu satırı dahil ederiz.
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
constructor
Verilen dosyayı ziplemek için şöyle yaparız.
public static void makeZip(String filename) throws IOException,
  ArchiveException {
  File sourceFile = new File(filename);

  final OutputStream out = new FileOutputStream(filename.substring(0,
    filename.lastIndexOf('.')) + ".zip");
  ZipArchiveOutputStream os = new ZipArchiveOutputStream(out);
  os.setUseZip64(Zip64Mode.AsNeeded);

  os.putArchiveEntry(new ZipArchiveEntry(sourceFile.getName()));
  IOUtils.copy(new FileInputStream(sourceFile), os);
  os.closeArchiveEntry();
  os.close();
}

7 Şubat 2019 Perşembe

FileFilterUtils Sınıfı

directoryFilter metodu
Şöyle yaparız.
pathFile.listFiles((java.io.FileFilter) FileFilterUtils.directoryFileFilter())

POI Excel Workbook Arayüzü

Giriş
Şu satırı dahil ederiz.
import org.apache.poi.ssf.usermodel.WorkBook;
close metodu
Şöyle yaparız.
workbook.close();
getSheetAt metodu
Sheet nesnesi döndürür.
Örnek
Şöyle yaparız
Workbook workbook = ...;
Sheet sheet = workbook.getSheetAt(0);
Örnek
Şöyle yaparız.
Sheet sheet = workbook.getSheetAt(0);

Compress ArchiveInputStream Sınıfı

Giriş
Abstract bir sınıftır. Bu sınıftan kalıtan sınıflar şöyle

ArArchiveInputStream, ArjArchiveInputStream, CpioArchiveInputStream, DumpArchiveInputStream, TarArchiveInputStream, ZipArchiveInputStream

constructor
Şöyle yaparız. ArchiveStreamFactory tarafından yaratılır.
try (ArchiveInputStream ais =
         asFactory.createArchiveInputStream(
           new BufferedInputStream(
             new FileInputStream(archive)))) {

  ...
}
getNextEntry metodu
Şöyle yaparız.
ArchiveEntry ae;
while ((ae = ais.getNextEntry()) != null) {

  if (ae.isDirectory()) {
    File dir = new File(archive.getParentFile(), ae.getName());
    dir.mkdirs();
    continue;
  }

  File f = new File(archive.getParentFile(), ae.getName());
  File parent = f.getParentFile();
  parent.mkdirs();
  try (OutputStream os = new FileOutputStream(f)) {
    IOUtils.copy(ais, os);
  } catch (IOException innerIoe) {
    ...
  }
}