List of usage examples for java.io UncheckedIOException UncheckedIOException
public UncheckedIOException(IOException cause)
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static void copyURLToFile(URL url, File dest) { try {//from w w w . j a v a 2 s .c o m FileUtils.copyURLToFile(url, dest); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:name.wramner.jmstools.analyzer.DataProvider.java
/** * Get a base64-encoded image for inclusion in an img tag with a chart with number of produced and consumed messages * per second.//from w ww. j a va2 s . c o m * * @return chart as base64 string. */ public String getBase64MessagesPerSecondImage() { TimeSeries timeSeriesConsumed = new TimeSeries("Consumed"); TimeSeries timeSeriesProduced = new TimeSeries("Produced"); TimeSeries timeSeriesTotal = new TimeSeries("Total"); for (PeriodMetrics m : getMessagesPerSecond()) { Second second = new Second(m.getPeriodStart()); timeSeriesConsumed.add(second, m.getConsumed()); timeSeriesProduced.add(second, m.getProduced()); timeSeriesTotal.add(second, m.getConsumed() + m.getProduced()); } TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(timeSeriesConsumed); timeSeriesCollection.addSeries(timeSeriesProduced); timeSeriesCollection.addSeries(timeSeriesTotal); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { JFreeChart chart = ChartFactory.createTimeSeriesChart("Messages per second (TPS)", "Time", "Messages", timeSeriesCollection); chart.getPlot().setBackgroundPaint(Color.WHITE); ChartUtilities.writeChartAsPNG(bos, chart, 1024, 500); } catch (IOException e) { throw new UncheckedIOException(e); } return "data:image/png;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); }
From source file:com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops.DeployCloudFoundryServerGroupAtomicOperation.java
@Nullable private File downloadPackageArtifact(DeployCloudFoundryServerGroupDescription description) { File file = null;//from w w w . jav a 2 s . com try { InputStream artifactInputStream = description.getArtifactCredentials() .download(description.getApplicationArtifact()); file = File.createTempFile(UUID.randomUUID().toString(), null); FileOutputStream fileOutputStream = new FileOutputStream(file); IOUtils.copy(artifactInputStream, fileOutputStream); fileOutputStream.close(); } catch (IOException e) { if (file != null) { file.delete(); } throw new UncheckedIOException(e); } return file; }
From source file:org.flowable.app.rest.service.BaseSpringRestTestCase.java
protected CloseableHttpResponse internalExecuteRequest(HttpUriRequest request, int expectedStatusCode, boolean addJsonContentType) { CloseableHttpResponse response = null; try {/* ww w. j a v a2s. c o m*/ if (addJsonContentType && request.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) { // Revert to default content-type request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); } response = client.execute(request); Assert.assertNotNull(response.getStatusLine()); int responseStatusCode = response.getStatusLine().getStatusCode(); if (expectedStatusCode != responseStatusCode) { LOGGER.info("Wrong status code : {}, but should be {}", responseStatusCode, expectedStatusCode); if (response.getEntity() != null) { LOGGER.info("Response body: {}", IOUtils.toString(response.getEntity().getContent(), "utf-8")); } } Assert.assertEquals(expectedStatusCode, responseStatusCode); httpResponses.add(response); return response; } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzer.java
private void extractFilesForMarkers() { if (!markers.isEmpty()) { StrTokenizer tokenizer = StrTokenizer.getCSVInstance(); tokenizer.setDelimiterChar(';'); listPerfAlyzerFiles(normalizedDir).stream().filter(perfAlyzerFile -> { // GC logs cannot split up here and need to explicitly handle markers later. // Load profiles contains the markers themselves and thus need to be filtered out as well. String fileName = perfAlyzerFile.getFile().getName(); return !fileName.contains("gclog") & !fileName.contains("[loadprofile]"); }).forEach(perfAlyzerFile -> markers.forEach(marker -> { try { PerfAlyzerFile markerFile = perfAlyzerFile.copy(); markerFile.setMarker(marker.getName()); Path destPath = normalizedDir.toPath().resolve(markerFile.getFile().toPath()); WritableByteChannel destChannel = newByteChannel(destPath, CREATE, WRITE); Path srcPath = normalizedDir.toPath().resolve(perfAlyzerFile.getFile().toPath()); NioUtils.lines(srcPath, UTF_8).filter(s -> { tokenizer.reset(s);//from w w w . j av a 2 s. c o m long timestamp = Long.parseLong(tokenizer.nextToken()); return marker.getLeftMillis() <= timestamp && marker.getRightMillis() > timestamp; }).forEach(s -> writeLineToChannel(destChannel, s, UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } })); } }
From source file:objective.taskboard.followup.FollowUpHelper.java
public static void toJsonFile(FollowUpData data, File file) { Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()) .setPrettyPrinting().create(); try (OutputStream stream = new FileOutputStream(file)) { OutputStreamWriter writer = new OutputStreamWriter(stream); gson.toJson(data, writer);//from w w w. j a va 2 s . c om writer.flush(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static void serialize(Object obj, File file) { if (!file.exists()) { write(file, ""); }/*from w ww . j a v a 2 s . co m*/ try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { oos.writeObject(obj); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.wildfly.swarm.microprofile.openapi.runtime.OpenApiAnnotationScanner.java
private static void index(Indexer indexer, String resName) { ClassLoader cl = OpenApiAnnotationScanner.class.getClassLoader(); try (InputStream klazzStream = cl.getResourceAsStream(resName)) { indexer.index(klazzStream);/*from w w w. jav a 2 s. c o m*/ } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }
From source file:org.apache.geode.distributed.LauncherIntegrationTestCase.java
private void givenPortInUse(final int port, InetAddress bindAddress) { try {//from w w w. ja v a2 s . c o m socket = SocketCreatorFactory.createNonDefaultInstance(false, false, null, null, System.getProperties()) .createServerSocket(port, 50, bindAddress, -1); assertThat(socket.isBound()).isTrue(); assertThat(socket.isClosed()).isFalse(); assertThat(isPortAvailable(port, SOCKET)).isFalse(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.discovery.darchrow.io.IOWriteUtil.java
/** * .// w ww . j a v a2 s . c om * * <ul> * <li>?,, (?? )</li> * <li>,? {@link FileWriteMode#APPEND}??</li> * </ul> * * @param filePath * * @param content * * @param encode * ?,isNullOrEmpty, {@link CharsetType#GBK}? {@link CharsetType} * @param fileWriteMode * ? * @see FileWriteMode * @see CharsetType * @see java.io.FileOutputStream#FileOutputStream(File, boolean) */ public static void write(String filePath, String content, String encode, FileWriteMode fileWriteMode) { //TODO ? ???? if (Validator.isNullOrEmpty(encode)) { encode = CharsetType.GBK; } // **************************************************************************8 File file = new File(filePath); FileUtil.createDirectoryByFilePath(filePath); OutputStream outputStream = null; try { outputStream = FileUtil.getFileOutputStream(filePath, fileWriteMode); //TODO ? write(inputStream, outputStream); Writer outputStreamWriter = new OutputStreamWriter(outputStream, encode); Writer writer = new PrintWriter(outputStreamWriter); writer.write(content); writer.close(); if (LOGGER.isInfoEnabled()) { LOGGER.info("fileWriteMode:[{}],encode:[{}],contentLength:[{}],fileSize:[{}],absolutePath:[{}]", fileWriteMode, encode, content.length(), FileUtil.getFileFormatSize(file), file.getAbsolutePath()); } outputStream.close(); } catch (IOException e) { throw new UncheckedIOException(e); } finally { IOUtils.closeQuietly(outputStream); } }