2 * DictZip command line interface.
4 * This is a part of DictZip-java library.
6 * Copyright (C) 2016 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;
26 import java.util.Locale;
27 import java.util.ResourceBundle;
28 import java.io.IOException;
31 * dictzip/dictunzip main class.
32 * @author Hiroshi Miura
34 public final class Main {
36 * The localized strings are kept in a separate file.
38 private static ResourceBundle messages = ResourceBundle.getBundle(
39 "org/dict/zip/cli/Bundle", Locale.getDefault());
41 private static CommandLine commandLine = new CommandLine();
46 * @param argv command line argument
48 public static void main(final String[] argv) {
49 int res = commandLine.parse(argv);
50 // If error in command line, exit with code
54 for (String fName: commandLine.getTargetFiles()) {
57 if (commandLine.options.isList()) {
58 commandLine.options.setKeep(true);
59 dict = new DictData(fName, null);
61 } else if (commandLine.options.isDecompress()) {
62 String extractFile = DictZipUtils.uncompressedFileName(fName);
63 long start = commandLine.options.getStart();
64 int size = commandLine.options.getSize();
65 dict = new DictData(extractFile, fName);
66 dict.doUnzip(start, size);
67 } else { // compression.
68 String zippedFile = DictZipUtils.compressedFileName(fName);
69 dict = new DictData(fName, zippedFile);
72 if (!commandLine.options.isKeep()) {
73 File targetFile = new File(fName);
74 if (!targetFile.delete()) {
75 System.err.println(messages.getString("main.delete.error"));
79 } catch (IOException ex) {
80 System.err.println(messages.getString("main.io.error"));
81 System.err.println(ex.getLocalizedMessage());