Exemplo n.º 1
0
  public void processInDirectory() {
    //
    // распакуем все файлы из каталага in
    //
    final int BUFFER_SIZE = 4096;
    SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    final String sessionDate = df.format(new Date());
    //
    // ищем файлы с ответом
    logger.info("Обрабатываем входной каталог " + ABS_INPUT_DIR);
    try {
      File[] directoryList =
          (new File(ABS_INPUT_DIR))
              .listFiles(
                  pathname -> !pathname.isDirectory() && pathname.getName().endsWith(".zip"));
      //
      // распаковываем каждый zip
      //
      for (File curFile : directoryList) {
        logger.info("Распаковываем " + curFile.getName());
        //
        // открываем архив
        //
        FileInputStream fis = new FileInputStream(curFile);
        ZipInputStream zis = new ZipInputStream(fis);
        ZipEntry zipEntry;
        while ((zipEntry = zis.getNextEntry()) != null) {
          //
          // пропускаем директории, т.к. их быть не должно
          //
          if (zipEntry.isDirectory()) continue;
          //
          // из архива извлекаем только xml !!!
          //
          if (zipEntry.getName().endsWith(".xml")) {
            File unzippedFile = new File(ABS_INPUT_DIR + "/" + zipEntry.getName());
            logger.info("Извлекаем файл " + zipEntry.getName());
            FileOutputStream fos = new FileOutputStream(unzippedFile);
            byte[] buffer = new byte[BUFFER_SIZE];
            int count = 0;
            while ((count = zis.read(buffer)) > 0) {
              fos.write(buffer, 0, count);
            }
            fos.close();
          }
          zis.closeEntry();
        }
        zis.close();
        fis.close();
        Files.move(
            curFile.toPath(),
            Paths.get(ABS_ARCH_IN_DIR + "/" + sessionDate + "-" + curFile.getName()));
      }
    } catch (Exception e) {
      logger.error(e.getMessage());
      e.printStackTrace();
    }

    logger.info("Обработан входной каталог " + ABS_INPUT_DIR);
  }
Exemplo n.º 2
0
 private void appendZipFile(ZipOutputStream dataZip, File file) throws Exception {
   logger.info("В архив записываем файл " + file.getName() + " -> " + file.getAbsolutePath());
   // открываем поток для чтения файла
   FileInputStream fis = new FileInputStream(file);
   byte[] buffer = new byte[fis.available()];
   fis.read(buffer);
   fis.close();
   // создаем элемент архива
   ZipEntry zipEntry = new ZipEntry(file.getName());
   // записываем данные в элемент архива и закрываем элемент
   dataZip.putNextEntry(zipEntry);
   dataZip.write(buffer);
   dataZip.closeEntry();
 }
Exemplo n.º 3
0
  private void laden(Path saveName) throws IOException {
    Properties prop = new Properties();

    FileInputStream in = new FileInputStream(saveName.toString());
    prop.load(in);

    for (int i = 0; prop.containsKey(String.format("quellMenu%d", i)); i++)
      quellListModel.addElement(
          new ListItem(
              Paths.get(prop.getProperty(String.format("quellMenu%d", i))),
              Paths.get(prop.getProperty(String.format("quellMenu%d", i)))));
    for (int i = 0; prop.containsKey(String.format("zielMenu%d", i)); i++)
      zielListModel.addElement(
          new ListItem(
              Paths.get(prop.getProperty(String.format("zielMenu%d", i))),
              Paths.get(prop.getProperty(String.format("zielMenu%d", i)))));

    in.close();
  }