Some initial refactoring in dicttool. (A1)
Bug: 7388852 Change-Id: I5ff70d12f3a8096ae6fb8cd4883a32ffe1683c9bmain
parent
b5a15bc076
commit
77fe603a3d
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.inputmethod.latin.dicttool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Class grouping utilities for offline dictionary making.
|
||||
*
|
||||
* Those should not be used on-device, essentially because they are quite
|
||||
* liberal about I/O and performance.
|
||||
*/
|
||||
public class BinaryDictOffdeviceUtils {
|
||||
public static void copy(final InputStream input, final OutputStream output) throws IOException {
|
||||
final byte[] buffer = new byte[1000];
|
||||
final BufferedInputStream in = new BufferedInputStream(input);
|
||||
final BufferedOutputStream out = new BufferedOutputStream(output);
|
||||
for (int readBytes = in.read(buffer); readBytes >= 0; readBytes = in.read(buffer))
|
||||
output.write(buffer, 0, readBytes);
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
|
@ -36,14 +36,6 @@ public class Compress {
|
|||
return new GZIPInputStream(in);
|
||||
}
|
||||
|
||||
public static void copy(final InputStream input, final OutputStream output) throws IOException {
|
||||
final byte[] buffer = new byte[1000];
|
||||
for (int readBytes = input.read(buffer); readBytes >= 0; readBytes = input.read(buffer))
|
||||
output.write(buffer, 0, readBytes);
|
||||
input.close();
|
||||
output.close();
|
||||
}
|
||||
|
||||
static public class Compressor extends Dicttool.Command {
|
||||
public static final String COMMAND = "compress";
|
||||
public static final String STDIN_OR_STDOUT = "-";
|
||||
|
@ -66,7 +58,7 @@ public class Compress {
|
|||
: new FileInputStream(new File(inFilename));
|
||||
final OutputStream output = outFilename.equals(STDIN_OR_STDOUT) ? System.out
|
||||
: new FileOutputStream(new File(outFilename));
|
||||
copy(input, new GZIPOutputStream(output));
|
||||
BinaryDictOffdeviceUtils.copy(input, new GZIPOutputStream(output));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +84,7 @@ public class Compress {
|
|||
: new FileInputStream(new File(inFilename));
|
||||
final OutputStream output = outFilename.equals(STDIN_OR_STDOUT) ? System.out
|
||||
: new FileOutputStream(new File(outFilename));
|
||||
copy(new GZIPInputStream(input), output);
|
||||
BinaryDictOffdeviceUtils.copy(new GZIPInputStream(input), output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue