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;
21 import java.nio.channels.FileChannel;
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");
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] + "'");
39 skipHtmlOpt = args[2].equals("skipHtmlOpt");
41 final String inname = args[0];
42 final String outname = args[1];
45 in = new FileInputStream(inname);
46 } catch (FileNotFoundException e) {
47 System.out.println("Could not open input file '" + inname + "'");
48 System.out.println(e);
51 final Dictionary dictionary = new Dictionary(in.getChannel());
52 if (dictionary.dictFileVersion <= 6) {
53 System.out.println("Input dictionary is already v6 or older!");
56 if (skipHtmlOpt && dictionary.htmlEntries.size() == 0) {
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);
67 if (out.length() > 0) {
68 System.out.println("Output file '" + outname + "' already exists, aborting!");
71 dictionary.writev6(out, skipHtml);