2 * DictZip command line interface.
4 * This is a part of DictZip-java library.
6 * Copyright (C) 2016,2022 Hiroshi Miura
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 package org.dict.zip.cli;
25 import org.dict.zip.DictZipFiles;
26 import org.dict.zip.DictZipHeader.CompressionLevel;
29 import java.util.Locale;
30 import java.util.ResourceBundle;
31 import java.io.IOException;
34 * dictzip/dictunzip main class.
35 * @author Hiroshi Miura
37 public final class Main {
39 * The localized strings are kept in a separate file.
41 private static ResourceBundle messages = ResourceBundle.getBundle(
42 "org/dict/zip/cli/Bundle", Locale.getDefault());
44 private static CommandLine commandLine = new CommandLine();
49 * @param argv command line argument
51 public static void main(final String[] argv) {
52 int res = commandLine.parse(argv);
53 // If error in command line, exit with code
56 } else if (res == 1) {
60 for (String fName: commandLine.getTargetFiles()) {
63 if (commandLine.options.isList()) {
64 commandLine.options.setKeep(true);
65 dict = new DictData(fName, null);
67 } else if (commandLine.options.isTest()) {
68 boolean result = false;
70 result = DictZipFiles.checkDictZipFile(fName);
71 } catch (IOException e) {
72 System.err.println(e.getMessage());
78 System.err.println(messages.getString("main.test.error"));
81 } else if (commandLine.options.isDecompress()) {
82 String extractFile = DictZipUtils.uncompressedFileName(fName);
83 long start = commandLine.options.getStart();
84 int size = commandLine.options.getSize();
85 dict = new DictData(extractFile, fName);
86 dict.doUnzip(start, size);
87 } else { // compression.
88 String zippedFile = DictZipUtils.compressedFileName(fName);
89 CompressionLevel level = commandLine.options.getLevel();
90 dict = new DictData(fName, zippedFile);
93 if (!commandLine.options.isKeep()) {
94 File targetFile = new File(fName);
95 if (!targetFile.delete()) {
96 System.err.println(messages.getString("main.delete.error"));
100 } catch (IOException ex) {
101 System.err.println(messages.getString("main.io.error"));
102 System.err.println(ex.getLocalizedMessage());