1 // Copyright 2020 Reimar Döffinger. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 package com.hughes.android.dictionary.engine;
17 import java.io.FileInputStream;
18 import java.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.RandomAccessFile;
22 public class ConvertToV6 {
23 public static void main(final String[] args) throws IOException {
24 if (args.length != 2 && args.length != 3) {
25 System.out.println("Usage: ConvertToV6 <input.v007> <output.v006> [skipHtml]");
26 System.out.println("If the option third argument is given as 'skipHtml'");
27 System.out.println("the v6 dictionary will be without all HTML entries to reduce its size");
30 boolean skipHtml = false;
31 boolean skipHtmlOpt = false;
32 if (args.length == 3) {
33 if (!args[2].equals("skipHtml") && !args[2].equals("skipHtmlOpt")) {
34 System.out.println("Unknown extra argument '" + args[2] + "'");
38 skipHtmlOpt = args[2].equals("skipHtmlOpt");
40 final String inname = args[0];
41 final String outname = args[1];
44 in = new FileInputStream(inname);
45 } catch (FileNotFoundException e) {
46 System.out.println("Could not open input file '" + inname + "'");
47 System.out.println(e);
50 final Dictionary dictionary = new Dictionary(in.getChannel());
51 if (dictionary.dictFileVersion <= 6) {
52 System.out.println("Input dictionary is already v6 or older!");
55 if (skipHtmlOpt && dictionary.htmlEntries.size() == 0) {
60 out = new RandomAccessFile(outname, "rw");
61 } catch (FileNotFoundException e) {
62 System.out.println("Could not open output file '" + outname + "'");
63 System.out.println(e);
66 if (out.length() > 0) {
67 System.out.println("Output file '" + outname + "' already exists, aborting!");
70 new DictionaryV6Writer(dictionary).writev6(out, skipHtml);