@Test(expected = IllegalArgumentException.class) public void readFileAsTextNotFoundWithEmptAlternateLocation() { FileSystemUtil.readFileAsText("/not/existing/file.txt", ""); }
public static String readFileAsText(String filename) { try (InputStream is = openStream(filename)) { String result = CharStreams.toString(new InputStreamReader(is, Charset.defaultCharset())); if (StringUtils.isEmpty(result)) { throw new IllegalArgumentException("File '" + filename + "' is empty."); } return result; } catch (IOException e) { throw new IllegalStateException("Error reading file '" + filename + "': " + e.getMessage(), e); } }
FileSystemUtil { public static String readFileAsText(String filename) { try (InputStream is = openStream(filename)) { String result = CharStreams.toString(new InputStreamReader(is, Charset.defaultCharset())); if (StringUtils.isEmpty(result)) { throw new IllegalArgumentException("File '" + filename + "' is empty."); } return result; } catch (IOException e) { throw new IllegalStateException("Error reading file '" + filename + "': " + e.getMessage(), e); } } }
FileSystemUtil { public static String readFileAsText(String filename) { try (InputStream is = openStream(filename)) { String result = CharStreams.toString(new InputStreamReader(is, Charset.defaultCharset())); if (StringUtils.isEmpty(result)) { throw new IllegalArgumentException("File '" + filename + "' is empty."); } return result; } catch (IOException e) { throw new IllegalStateException("Error reading file '" + filename + "': " + e.getMessage(), e); } } private  FileSystemUtil(); }
FileSystemUtil { public static String readFileAsText(String filename) { try (InputStream is = openStream(filename)) { String result = CharStreams.toString(new InputStreamReader(is, Charset.defaultCharset())); if (StringUtils.isEmpty(result)) { throw new IllegalArgumentException("File '" + filename + "' is empty."); } return result; } catch (IOException e) { throw new IllegalStateException("Error reading file '" + filename + "': " + e.getMessage(), e); } } private  FileSystemUtil(); static boolean checkFileOrResourceExists(String filename); static void assertFileOrResourceExists(String filename); static String readFileAsText(String filename); static String readFileAsText(String fileName, String alternateDir); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void writeStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void appendStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static byte[] readBytesFromFile(String filename); static void deleteDirectoryQuietly(String rootDirName); }
FileSystemUtil { public static String readFileAsText(String filename) { try (InputStream is = openStream(filename)) { String result = CharStreams.toString(new InputStreamReader(is, Charset.defaultCharset())); if (StringUtils.isEmpty(result)) { throw new IllegalArgumentException("File '" + filename + "' is empty."); } return result; } catch (IOException e) { throw new IllegalStateException("Error reading file '" + filename + "': " + e.getMessage(), e); } } private  FileSystemUtil(); static boolean checkFileOrResourceExists(String filename); static void assertFileOrResourceExists(String filename); static String readFileAsText(String filename); static String readFileAsText(String fileName, String alternateDir); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void writeStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void appendStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static byte[] readBytesFromFile(String filename); static void deleteDirectoryQuietly(String rootDirName); static final String CLASSPATH_PREFIX; }