]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/ConvertToV6.java
e9b7c8f0eebac7393023d5da53854551892ce6b1
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / ConvertToV6.java
1 // Copyright 2020 Reimar Döffinger. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.io.FileInputStream;
18 import java.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.RandomAccessFile;
21 import java.nio.channels.FileChannel;
22
23 public class ConvertToV6 {
24     public static void main(final String[] args) throws IOException {
25         if (args.length != 2 && args.length != 3) {
26             System.out.println("Usage: ConvertToV6 <input.v007> <output.v006> [skipHtml]");
27             System.out.println("If the option third argument is given as 'skipHtml'");
28             System.out.println("the v6 dictionary will be without all HTML entries to reduce its size");
29             return;
30         }
31         boolean skipHtml = false;
32         boolean skipHtmlOpt = false;
33         if (args.length == 3) {
34             if (!args[2].equals("skipHtml") && !args[2].equals("skipHtmlOpt")) {
35                 System.out.println("Unknown extra argument '" + args[2] + "'");
36                 return;
37             }
38             skipHtml = true;
39             skipHtmlOpt = args[2].equals("skipHtmlOpt");
40         }
41         final String inname = args[0];
42         final String outname = args[1];
43         FileInputStream in;
44         try {
45             in = new FileInputStream(inname);
46         } catch (FileNotFoundException e) {
47             System.out.println("Could not open input file '" + inname + "'");
48             System.out.println(e);
49             return;
50         }
51         final Dictionary dictionary = new Dictionary(in.getChannel());
52         if (dictionary.dictFileVersion <= 6) {
53             System.out.println("Input dictionary is already v6 or older!");
54             return;
55         }
56         if (skipHtmlOpt && dictionary.htmlEntries.size() == 0) {
57             System.exit(3);
58         }
59         RandomAccessFile out;
60         try {
61             out = new RandomAccessFile(outname, "rw");
62         } catch (FileNotFoundException e) {
63             System.out.println("Could not open output file '" + outname + "'");
64             System.out.println(e);
65             return;
66         }
67         if (out.length() > 0) {
68             System.out.println("Output file '" + outname + "' already exists, aborting!");
69             return;
70         }
71         new DictionaryV6Writer(dictionary).writev6(out, skipHtml);
72         out.close();
73         in.close();
74     }
75 }