List of usage examples for java.io UncheckedIOException UncheckedIOException
public UncheckedIOException(IOException cause)
From source file:com.mgmtp.perfload.perfalyzer.util.IoUtilities.java
/** * Reads the last line of the specified file. * * @param file/*from ww w .ja v a 2 s . com*/ * the file * @param charset * the charset */ public static String readLastLine(final File file, final Charset charset) { try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { long length = raf.length() - 1; ByteArrayOutputStream baos = new ByteArrayOutputStream(80); for (long pos = length; pos != -1; --pos) { // we start from the end of the file raf.seek(pos); int readByte = raf.readByte(); if (readByte == 10) { // this is the case if the file ends with a line-break if (pos == length) { continue; } break; } else if (readByte == 13) { // this is the case if the file ends with a line-break (Windows only) if (pos == length - 1) { continue; } break; } baos.write(readByte); } byte[] bytes = baos.toByteArray(); // reverse array because it was filled backwards ArrayUtils.reverse(bytes); // turn into string respecting the charset return new String(bytes, charset); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
From source file:com.discovery.darchrow.io.FileUtil.java
/** * ?.??.<br>//from w w w . ja va 2 s.com * {@link java.io.FileInputStream} ????.<br> * ??? {@link java.io.FileReader} * * @param file * ?. * @return FileInputStream * @see java.io.FileInputStream */ public static final FileInputStream getFileInputStream(File file) { try { // ???? FileNotFoundException. FileInputStream fileInputStream = new FileInputStream(file); return fileInputStream; } catch (FileNotFoundException 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 minute./*from www .j a v a 2 s . co m*/ * * @return chart as base64 string. */ public String getBase64MessagesPerMinuteImage() { TimeSeries timeSeriesConsumed = new TimeSeries("Consumed"); TimeSeries timeSeriesProduced = new TimeSeries("Produced"); TimeSeries timeSeriesTotal = new TimeSeries("Total"); for (PeriodMetrics m : getMessagesPerMinute()) { Minute minute = new Minute(m.getPeriodStart()); timeSeriesConsumed.add(minute, m.getConsumed()); timeSeriesProduced.add(minute, m.getProduced()); timeSeriesTotal.add(minute, 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 minute", "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.github.blindpirate.gogradle.util.IOUtils.java
public static void chmodAddX(Path filePath) { try {// w w w.j a v a 2 s .c o m if (Os.getHostOs() != Os.WINDOWS) { Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("rwx------")); } } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java
public static void prepareInputOutput(Path in, Path out) throws IOException { if (!Files.exists(in)) throw new IOException(in.toString() + " does not exist. Ensure it exists and re-run this program."); Optional<Path> outPath = Optional.ofNullable(out.getParent()); outPath.ifPresent(p -> {/* ww w . j av a2 s .c o m*/ if (!Files.exists(p)) { LOGGER.debug("Attempting to create output directory: {}", outPath.toString()); try { Files.createDirectories(p); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }
From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkListDecrypter.java
void copy(InputStream is, byte[] checksum, ChunkStore store) { try {// w ww . j a va 2 s .c om Optional<OutputStream> os = store.outputStream(checksum); if (os.isPresent()) { logger.debug("-- copy() - copying chunk into store: 0x{}", Hex.toHexString(checksum)); doCopy(is, os.get()); } else { logger.debug("-- copy() - store now already contains chunk: 0x{}", Hex.toHexString(checksum)); } } catch (IOException ex) { throw new UncheckedIOException(ex); } finally { IOUtils.closeQuietly(is); } }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static Path toRealPath(Path path) { try {//from w w w . j a v a 2 s .c om return path.toRealPath(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java
public static void append(String content, OutputStreamWriter outputStreamWriter) { try {/*from w w w. j a v a2s . co m*/ outputStreamWriter.append(content); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.ajoberstar.reckon.core.git.GitInventorySupplier.java
private Optional<Version> findParallel(RevWalk walk, RevCommit head, TaggedVersion candidate, Set<RevCommit> tagged) { try {//from w ww . j ava2s. co m walk.reset(); walk.setRevFilter(RevFilter.MERGE_BASE); walk.markStart(head); walk.markStart(candidate.getCommit()); RevCommit mergeBase = walk.next(); walk.reset(); walk.setRevFilter(RevFilter.ALL); boolean taggedSinceMergeBase = RevWalkUtils.find(walk, head, mergeBase).stream() .filter(tagged::contains).findAny().isPresent(); if (mergeBase != null && !taggedSinceMergeBase && !mergeBase.equals(head) && !mergeBase.equals(candidate.getCommit())) { return Optional.of(Versions.getNormal(candidate.getVersion())); } else { return Optional.empty(); } } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.apache.geode.distributed.LauncherIntegrationTestCase.java
protected String getWorkingDirectoryPath() { try {//from w ww .j a v a 2 s. c om return getWorkingDirectory().getCanonicalPath(); } catch (IOException e) { throw new UncheckedIOException(e); } }