List of usage examples for java.io UncheckedIOException UncheckedIOException
public UncheckedIOException(IOException cause)
From source file:org.obiba.mica.micaConfig.service.EntityConfigService.java
String mergeDefinition(String baseNode, String overrideNode) { try {// w w w . j a va 2 s. com return mergeDefinition(new ObjectMapper().readTree(baseNode), new ObjectMapper().readTree(overrideNode)) .toString(); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.AlexandriaCommand.java
private <T> T uncheckedRead(File file, Class<T> clazz) { try {/*from ww w .j a v a2 s . c om*/ return mapper.readValue(file, clazz); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.cloudbees.jenkins.support.util.OutputStreamSelectorTest.java
private void assertThatContentsWriteToTextOut(String contents) { try {/*from w ww. j a va2 s .com*/ selector.write(contents.getBytes(UTF_8)); selector.flush(); assertThat(binaryOut.toByteArray()).isEmpty(); assertThat(new String(textOut.toByteArray(), UTF_8)).isNotEmpty().isEqualTo(contents); } catch (IOException e) { throw new UncheckedIOException(e); } finally { selector.reset(); binaryOut.reset(); textOut.reset(); } }
From source file:objective.taskboard.utils.ZipUtils.java
public static byte[] zipToByteArray(Stream<ZipStreamEntry> stream) { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { zip(stream, outStream);/*from w w w . ja va2s . c om*/ return outStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.github.horrorho.inflatabledonkey.cloud.AuthorizeAssetsClient.java
FileGroups fileGroups(HttpClient httpClient, String dsPrsID, String contentBaseUrl, CloudKit.FileTokens fileTokens) throws UncheckedIOException { try {//from w w w . ja v a2 s . c o m HttpUriRequest request = AuthorizeGetRequestFactory.instance().newRequest(dsPrsID, contentBaseUrl, container, zone, fileTokens); return httpClient.execute(request, responseHandler); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
From source file:org.apache.geode.internal.process.AbstractProcessStreamReaderIntegrationTest.java
private void givenStartedProcess(final Class<?> mainClass) { try {// ww w.j ava 2s . c o m process = new ProcessBuilder(createCommandLine(mainClass)).start(); stdout = buildProcessStreamReader(process.getInputStream(), getReadingMode()); stderr = buildProcessStreamReader(process.getErrorStream(), getReadingMode()); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordToolIT.java
@SuppressWarnings("unchecked") public void testSetupPasswordToolAutoSetup() throws Exception { final String testConfigDir = System.getProperty("tests.config.dir"); logger.info("--> CONF: {}", testConfigDir); final Path configPath = PathUtils.get(testConfigDir); setSystemPropsForTool(configPath);// w ww. java2 s .c o m Response nodesResponse = client().performRequest("GET", "/_nodes/http"); Map<String, Object> nodesMap = entityAsMap(nodesResponse); Map<String, Object> nodes = (Map<String, Object>) nodesMap.get("nodes"); Map<String, Object> firstNode = (Map<String, Object>) nodes.entrySet().iterator().next().getValue(); Map<String, Object> firstNodeHttp = (Map<String, Object>) firstNode.get("http"); String nodePublishAddress = (String) firstNodeHttp.get("publish_address"); final int lastColonIndex = nodePublishAddress.lastIndexOf(':'); InetAddress actualPublishAddress = InetAddresses.forString(nodePublishAddress.substring(0, lastColonIndex)); InetAddress expectedPublishAddress = new NetworkService(Collections.emptyList()) .resolvePublishHostAddresses(Strings.EMPTY_ARRAY); final int port = Integer.valueOf(nodePublishAddress.substring(lastColonIndex + 1)); List<String> lines = Files.readAllLines(configPath.resolve("elasticsearch.yml")); lines = lines.stream() .filter(s -> s.startsWith("http.port") == false && s.startsWith("http.publish_port") == false) .collect(Collectors.toList()); lines.add(randomFrom("http.port", "http.publish_port") + ": " + port); if (expectedPublishAddress.equals(actualPublishAddress) == false) { lines.add("http.publish_address: " + InetAddresses.toAddrString(actualPublishAddress)); } Files.write(configPath.resolve("elasticsearch.yml"), lines, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING); MockTerminal mockTerminal = new MockTerminal(); SetupPasswordTool tool = new SetupPasswordTool(); final int status; if (randomBoolean()) { mockTerminal.addTextInput("y"); // answer yes to continue prompt status = tool.main(new String[] { "auto" }, mockTerminal); } else { status = tool.main(new String[] { "auto", "--batch" }, mockTerminal); } assertEquals(0, status); String output = mockTerminal.getOutput(); logger.info("CLI TOOL OUTPUT:\n{}", output); String[] outputLines = output.split("\\n"); Map<String, String> userPasswordMap = new HashMap<>(); Arrays.asList(outputLines).forEach(line -> { if (line.startsWith("PASSWORD ")) { String[] pieces = line.split(" "); String user = pieces[1]; String password = pieces[pieces.length - 1]; logger.info("user [{}] password [{}]", user, password); userPasswordMap.put(user, password); } }); assertEquals(4, userPasswordMap.size()); userPasswordMap.entrySet().forEach(entry -> { final String basicHeader = "Basic " + Base64.getEncoder() .encodeToString((entry.getKey() + ":" + entry.getValue()).getBytes(StandardCharsets.UTF_8)); try { Response authenticateResponse = client().performRequest("GET", "/_xpack/security/_authenticate", new BasicHeader("Authorization", basicHeader)); assertEquals(200, authenticateResponse.getStatusLine().getStatusCode()); Map<String, Object> userInfoMap = entityAsMap(authenticateResponse); assertEquals(entry.getKey(), userInfoMap.get("username")); } catch (IOException e) { throw new UncheckedIOException(e); } }); }
From source file:org.apache.geode.distributed.LauncherIntegrationTestCase.java
protected File givenPidFile(final Object content) { try {/*from w w w . jav a 2 s. co m*/ File file = new File(getWorkingDirectory(), getProcessType().getPidFileName()); FileWriter writer = new FileWriter(file); writer.write(String.valueOf(content)); writer.write("\n"); writer.flush(); writer.close(); assertTrue(file.exists()); return file; } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java
public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); if (args.length < 2) { LOGGER.info("Usage: {} {} {} {}", WebPostIngester.class.getName(), "/path/to/output/folder", "/path/to/web/.xml/file", "<additional/xml/file/paths>"); System.exit(1);/*from w w w . j a va 2 s. c o m*/ } Path outPath = Paths.get(args[0]); Optional.ofNullable(outPath.getParent()).ifPresent(p -> { if (!Files.exists(p)) try { Files.createDirectories(p); } catch (IOException e) { throw new UncheckedIOException(e); } }); if (!Files.isDirectory(outPath)) { LOGGER.error("Output path must be a directory."); System.exit(1); } WebPostIngester ing = new WebPostIngester(); for (int i = 1; i < args.length; i++) { Path lp = Paths.get(args[i]); LOGGER.info("On path: {}", lp.toString()); try { Communication c = ing.fromCharacterBasedFile(lp); new WritableCommunication(c).writeToFile(outPath.resolve(c.getId() + ".comm"), true); } catch (IngestException | ConcreteException e) { LOGGER.error("Caught exception during ingest on file: " + args[i], e); } } }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
public static Stream<CSVRecord> records(CSVFormat format, Path path) { try {// w w w .jav a 2 s .c o m String p = path.toString(); if (!p.contains("*")) { return p.endsWith(".gz") ? GZIPFiles.records(format, path) : p.endsWith(".bz2") ? BZIP2Files.records(format, path) : overridenRecords(format, path); } else { File file = path.toFile(); return Stream .of(file.getParentFile().listFiles( (dir, name) -> name.matches(file.getName().replace(".", "\\.").replace("*", ".+")))) .sorted().flatMap(f -> records(format, f)); } } catch (IOException e) { throw new UncheckedIOException(e); } }