Search in sources :

Example 56 with FileInputStream

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);
    }
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 57 with FileInputStream

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;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 58 with FileInputStream

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) GGATest(net.sf.marineapi.nmea.parser.GGATest) Test(org.junit.Test) BODTest(net.sf.marineapi.nmea.parser.BODTest)

Example 59 with FileInputStream

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);
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 60 with FileInputStream

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)6674 File (java.io.File)3110 IOException (java.io.IOException)3008 InputStream (java.io.InputStream)1744 FileOutputStream (java.io.FileOutputStream)1023 FileNotFoundException (java.io.FileNotFoundException)976 BufferedInputStream (java.io.BufferedInputStream)873 InputStreamReader (java.io.InputStreamReader)760 Test (org.junit.Test)680 BufferedReader (java.io.BufferedReader)622 Properties (java.util.Properties)613 ArrayList (java.util.ArrayList)368 DataInputStream (java.io.DataInputStream)328 OutputStream (java.io.OutputStream)299 ByteArrayInputStream (java.io.ByteArrayInputStream)268 ZipEntry (java.util.zip.ZipEntry)258 HashMap (java.util.HashMap)230 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)200 ByteArrayOutputStream (java.io.ByteArrayOutputStream)188 XmlPullParser (org.xmlpull.v1.XmlPullParser)185