List of usage examples for java.io IOException addSuppressed
public final synchronized void addSuppressed(Throwable exception)
From source file:edu.umd.umiacs.clip.tools.io.BZIP2Files.java
protected static Stream<String> lines(Path path) throws IOException { BufferedReader br = null;//from w w w . ja v a 2s .c o m try { br = new BufferedReader(new InputStreamReader( new BZip2CompressorInputStream(new BufferedInputStream(newInputStream(path), BUFFER_SIZE)), UTF_8.newDecoder().onMalformedInput(IGNORE))); return br.lines().onClose(asUncheckedRunnable(br)); } catch (IOException e) { try { br.close(); } catch (Exception ex) { try { e.addSuppressed(ex); } catch (Throwable ignore) { } } throw e; } }
From source file:edu.umd.umiacs.clip.tools.io.GZIPFiles.java
protected static Stream<String> lines(Path path) throws IOException { BufferedReader br = null;/* ww w.jav a 2s . c o m*/ try { br = new BufferedReader(new InputStreamReader( new GZIPInputStream(new BufferedInputStream(newInputStream(path), BUFFER_SIZE)), UTF_8.newDecoder().onMalformedInput(IGNORE))); return br.lines().onClose(asUncheckedRunnable(br)); } catch (IOException e) { try { br.close(); } catch (Exception ex) { try { e.addSuppressed(ex); } catch (Throwable ignore) { } } throw e; } }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
private static Stream<String> overridenLines(Path path) throws IOException { BufferedReader br = null;// w w w. j a v a 2 s . c om try { br = new BufferedReader( new InputStreamReader(new BufferedInputStream(newInputStream(path), BUFFER_SIZE), UTF_8.newDecoder().onMalformedInput(IGNORE))); return br.lines().onClose(asUncheckedRunnable(br)); } catch (IOException e) { try { br.close(); } catch (Exception ex) { try { e.addSuppressed(ex); } catch (Throwable ignore) { } } throw e; } }
From source file:io.druid.java.util.common.CompressionUtils.java
/** * Decompress an input stream from a file, based on the filename. *///from www . ja va2 s .c om public static InputStream decompress(final InputStream in, final String fileName) throws IOException { if (fileName.endsWith(GZ_SUFFIX)) { return gzipInputStream(in); } else if (fileName.endsWith(BZ2_SUFFIX)) { return new BZip2CompressorInputStream(in, true); } else if (fileName.endsWith(XZ_SUFFIX)) { return new XZCompressorInputStream(in, true); } else if (fileName.endsWith(ZIP_SUFFIX)) { // This reads the first file in the archive. final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8); try { final ZipEntry nextEntry = zipIn.getNextEntry(); if (nextEntry == null) { zipIn.close(); // No files in the archive - return an empty stream. return new ByteArrayInputStream(new byte[0]); } return zipIn; } catch (IOException e) { try { zipIn.close(); } catch (IOException e2) { e.addSuppressed(e2); } throw e; } } else { return in; } }
From source file:neembuu.httpserver.VFileEntity.java
@Override public InputStream getContent() throws IOException, IllegalStateException { return new InputStream() { long pos = startingOffset; @Override//from www .j a va2 s . c om public int read() throws IOException { throw new IllegalStateException("This is not used."); } @Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); //To change body of generated methods, choose Tools | Templates. } @Override public int read(byte[] b, int off, int len) throws IOException { ByteBuffer bb = ByteBuffer.wrap(b, 0, len); BlockingReadRequest brr = new BlockingReadRequest(bb, pos); try { af.read(new SimpleReadRequest(bb, pos)); } catch (Exception a) { IOException ioe = new IOException(); ioe.addSuppressed(a); } int read = brr.read(); pos += read; return read; } }; }
From source file:com.splicemachine.mrio.api.core.SMRecordReaderImpl.java
@Override public void close() throws IOException { IOException lastThrown = null; if (LOG.isDebugEnabled()) SpliceLogUtils.debug(LOG, "close"); if (localTxn != null) { try {//from ww w .ja v a 2 s . c om localTxn.commit(); } catch (IOException ioe) { try { localTxn.rollback(); } catch (Exception e) { ioe.addSuppressed(e); } lastThrown = ioe; } } if (activationHolder != null) { //activationHolder.close(); } for (AutoCloseable c : closeables) { if (c != null) { try { c.close(); } catch (Exception e) { if (lastThrown != null) lastThrown.addSuppressed(e); else lastThrown = e instanceof IOException ? (IOException) e : new IOException(e); } } } if (lastThrown != null) { throw lastThrown; } }
From source file:io.v.android.apps.reader.UserActionLogger.java
@Override public void close() throws IOException { IOException ex = null; if (mTouchPrinter != null) { try {/* w w w . j a va2s . c o m*/ mTouchPrinter.close(); } catch (IOException e) { ex = e; } finally { mTouchPrinter = null; } } if (mNavigationPrinter != null) { try { mNavigationPrinter.close(); } catch (IOException e) { if (ex != null) { ex.addSuppressed(e); } else { ex = e; } } finally { mNavigationPrinter = null; } } if (ex != null) { throw ex; } }
From source file:com.joyent.manta.util.AutoContinuingInputStream.java
/** * Attempts to build a continuation of the stream we are trying to read if our {@link #continuator} considers the * exception non-fatal, passing along the byte offset from which the continuation should pick up. * * @param originalIOException the exception from which we are attempting to recover * @throws IOException the exception if it is not recoverable, or an exception that may have occurred while * continuing/*from ww w. j a v a 2s . com*/ */ private void attemptRecovery(final IOException originalIOException) throws IOException { try { super.continueWith(this.continuator.buildContinuation(originalIOException, this.getBytesRead())); } catch (final UncheckedIOException | IOException ioe) { LOG.debug("Failed to automatically recover: {}", ioe.getMessage()); // if a different exception was thrown while recovering, add it as a suppressed exception if (originalIOException != ioe) { originalIOException.addSuppressed(ioe); } // rethrow the original exception throw originalIOException; } }
From source file:org.spf4j.perf.tsdb.TimeSeriesDatabase.java
public void reReadTableInfos() throws IOException { synchronized (path) { FileLock lock = ch.lock(0, Long.MAX_VALUE, true); try {/*ww w . j a v a 2s. co m*/ toc = new TableOfContents(file, toc.getLocation()); // reread toc readTableInfos(); } catch (IOException | RuntimeException e) { try { lock.release(); throw e; } catch (IOException ex) { ex.addSuppressed(e); throw ex; } } lock.release(); } }
From source file:org.spf4j.perf.tsdb.TimeSeriesDatabase.java
public void addTSTable(final String tableName, final byte[] tableMetaData, final int sampleTime, final String[] columnNames, final byte[][] columnMetaData) throws IOException { synchronized (path) { if (hasTSTable(tableName)) { throw new IllegalArgumentException("group already exists " + tableName); }//from ww w.ja v a2 s.co m flush(); FileLock lock = ch.lock(); TSTable colInfo; try { readLastTableInfo(); //write column information at the end of the file. file.seek(file.length()); colInfo = new TSTable(tableName, tableMetaData, columnNames, columnMetaData, sampleTime, file.getFilePointer()); colInfo.writeTo(file); //update refferences to this new TableInfo. if (lastTableInfo != null) { lastTableInfo.setNextColumnInfo(colInfo.getLocation(), file); } else { toc.setFirstTableInfo(colInfo.getLocation(), file); } toc.setLastTableInfo(colInfo.getLocation(), file); } catch (IOException | RuntimeException e) { try { lock.release(); throw e; } catch (IOException ex) { ex.addSuppressed(e); throw ex; } } lock.release(); lastTableInfo = colInfo; tables.put(tableName, colInfo); } }