use of java.io.FileInputStream in project languagetool by languagetool-org.
the class HTTPServerConfig method parseConfigFile.
private void parseConfigFile(File file, boolean loadLangModel) {
try {
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(file)) {
props.load(fis);
maxTextLength = Integer.parseInt(getOptionalProperty(props, "maxTextLength", Integer.toString(Integer.MAX_VALUE)));
maxCheckTimeMillis = Long.parseLong(getOptionalProperty(props, "maxCheckTimeMillis", "-1"));
requestLimit = Integer.parseInt(getOptionalProperty(props, "requestLimit", "0"));
requestLimitPeriodInSeconds = Integer.parseInt(getOptionalProperty(props, "requestLimitPeriodInSeconds", "0"));
trustXForwardForHeader = Boolean.valueOf(getOptionalProperty(props, "trustXForwardForHeader", "false"));
maxWorkQueueSize = Integer.parseInt(getOptionalProperty(props, "maxWorkQueueSize", "0"));
if (maxWorkQueueSize < 0) {
throw new IllegalArgumentException("maxWorkQueueSize must be >= 0: " + maxWorkQueueSize);
}
String langModel = getOptionalProperty(props, "languageModel", null);
if (langModel != null && loadLangModel) {
setLanguageModelDirectory(langModel);
}
maxCheckThreads = Integer.parseInt(getOptionalProperty(props, "maxCheckThreads", "10"));
if (maxCheckThreads < 1) {
throw new IllegalArgumentException("Invalid value for maxCheckThreads, must be >= 1: " + maxCheckThreads);
}
mode = getOptionalProperty(props, "mode", "LanguageTool").equalsIgnoreCase("AfterTheDeadline") ? Mode.AfterTheDeadline : Mode.LanguageTool;
if (mode == Mode.AfterTheDeadline) {
System.out.println("WARNING: The AfterTheDeadline mode has been deprecated and will be removed in the next version of LanguageTool");
atdLanguage = Languages.getLanguageForShortCode(getProperty(props, "afterTheDeadlineLanguage", file));
}
String rulesConfigFilePath = getOptionalProperty(props, "rulesFile", null);
if (rulesConfigFilePath != null) {
rulesConfigFile = new File(rulesConfigFilePath);
if (!rulesConfigFile.exists() || !rulesConfigFile.isFile()) {
throw new RuntimeException("Rules Configuration file can not be found: " + rulesConfigFile);
}
}
cacheSize = Integer.parseInt(getOptionalProperty(props, "cacheSize", "0"));
if (cacheSize < 0) {
throw new IllegalArgumentException("Invalid value for cacheSize: " + cacheSize + ", use 0 to deactivate cache");
}
String warmUpStr = getOptionalProperty(props, "warmUp", "false");
if (warmUpStr.equals("true")) {
warmUp = true;
} else if (warmUpStr.equals("false")) {
warmUp = false;
} else {
throw new IllegalArgumentException("Invalid value for warmUp: '" + warmUpStr + "', use 'true' or 'false'");
}
}
} catch (IOException e) {
throw new RuntimeException("Could not load properties from '" + file + "'", e);
}
}
use of java.io.FileInputStream in project libgdx by libgdx.
the class SharedLibraryLoader method extractFile.
private File extractFile(String sourcePath, String sourceCrc, File extractedFile) throws IOException {
String extractedCrc = null;
if (extractedFile.exists()) {
try {
extractedCrc = crc(new FileInputStream(extractedFile));
} catch (FileNotFoundException ignored) {
}
}
// If file doesn't exist or the CRC doesn't match, extract it to the temp dir.
if (extractedCrc == null || !extractedCrc.equals(sourceCrc)) {
try {
InputStream input = readFile(sourcePath);
extractedFile.getParentFile().mkdirs();
FileOutputStream output = new FileOutputStream(extractedFile);
byte[] buffer = new byte[4096];
while (true) {
int length = input.read(buffer);
if (length == -1)
break;
output.write(buffer, 0, length);
}
input.close();
output.close();
} catch (IOException ex) {
throw new GdxRuntimeException("Error extracting file: " + sourcePath + "\nTo: " + extractedFile.getAbsolutePath(), ex);
}
}
return extractedFile;
}
use of java.io.FileInputStream in project marine-api by ktuukkan.
the class SentenceReaderTest method testSetInputStream.
@Test
public void testSetInputStream() throws Exception {
File file = new File("src/test/resources/data/Garmin-GPS76.txt");
InputStream stream = new FileInputStream(file);
reader.setInputStream(stream);
}
use of java.io.FileInputStream in project marine-api by ktuukkan.
the class SentenceReaderTest method setUp.
@Before
public void setUp() throws Exception {
File file = new File(TEST_DATA);
stream = new FileInputStream(file);
reader = new SentenceReader(stream);
dummyListener = new DummySentenceListener();
testListener = new TestSentenceListener();
reader.addSentenceListener(dummyListener);
reader.addSentenceListener(testListener, SentenceId.GGA);
}
use of java.io.FileInputStream in project Lazy by l123456789jy.
the class FileUtils method readFileContent.
/**
* 读取文本文件内容,以行的形式读取
*
* @param filePathAndName 带有完整绝对路径的文件名
* @param encoding 文本文件打开的编码方式 例如 GBK,UTF-8
* @param sep 分隔符 例如:#,默认为\n;
* @param bufLen 设置缓冲区大小
* @return String 返回文本文件的内容
*/
public static String readFileContent(String filePathAndName, String encoding, String sep, int bufLen) {
if (filePathAndName == null || filePathAndName.equals("")) {
return "";
}
if (sep == null || sep.equals("")) {
sep = "\n";
}
if (!new File(filePathAndName).exists()) {
return "";
}
StringBuffer str = new StringBuffer("");
FileInputStream fs = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
fs = new FileInputStream(filePathAndName);
if (encoding == null || encoding.trim().equals("")) {
isr = new InputStreamReader(fs);
} else {
isr = new InputStreamReader(fs, encoding.trim());
}
br = new BufferedReader(isr, bufLen);
String data = "";
while ((data = br.readLine()) != null) {
str.append(data).append(sep);
}
} catch (IOException e) {
} finally {
try {
if (br != null)
br.close();
if (isr != null)
isr.close();
if (fs != null)
fs.close();
} catch (IOException e) {
}
}
return str.toString();
}
Aggregations