private void checkException() throws IOException { if (this.exception == null) return; if (this.exception instanceof IOException) { throw ExceptionUtil.wrap(null, (IOException) this.exception); } else if (this.exception instanceof RuntimeException) { throw ExceptionUtil.wrap(null, (RuntimeException) this.exception); } else { throw ExceptionUtil.wrap(null, this.exception, IOException.class); } }
private void checkException() throws IOException { if (this.exception == null) return; if (this.exception instanceof IOException) { throw ExceptionUtil.wrap(null, (IOException) this.exception); } else if (this.exception instanceof RuntimeException) { throw ExceptionUtil.wrap(null, (RuntimeException) this.exception); } else { throw ExceptionUtil.wrap(null, this.exception, IOException.class); } }
public NestedZipFileStream(File file) throws IOException { super(null); try { this.zipFile = new ZipFile(file); } catch (IOException ioe) { throw ExceptionUtil.wrap("Opening '" + file + "'", ioe); } }
/** * Unmaps a {@link MappedByteBuffer} that originated from {@link FileChannel#map(MapMode, long, long)}. Substitutes * the {@code MappedByteBuffer.unmap()} that is missing painfully from the JRE. */ private static void unmap(final MappedByteBuffer mappedByteBuffer) { // Only ORACLE knows why the "sun.nio.ch.FileChannelImpl.unmap()" method is PRIVATE - there is no other way to // unmap a MappedByteBuffer! try { PipeFactory.UNMAP_METHOD.invoke(null, mappedByteBuffer); } catch (Exception e) { throw ExceptionUtil.wrap("Unmapping file channel", e, RuntimeException.class); } } private static final Method UNMAP_METHOD;
/** * Unmaps a {@link MappedByteBuffer} that originated from {@link FileChannel#map(MapMode, long, long)}. Substitutes * the {@code MappedByteBuffer.unmap()} that is missing painfully from the JRE. */ private static void unmap(final MappedByteBuffer mappedByteBuffer) { // Only ORACLE knows why the "sun.nio.ch.FileChannelImpl.unmap()" method is PRIVATE - there is no other way to // unmap a MappedByteBuffer! try { PipeFactory.UNMAP_METHOD.invoke(null, mappedByteBuffer); } catch (Exception e) { throw ExceptionUtil.wrap("Unmapping file channel", e, RuntimeException.class); } } private static final Method UNMAP_METHOD;
private static URL fileUrl(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException mue) { throw ExceptionUtil.wrap(file.toString(), mue, IllegalStateException.class); } } }
@NotNullByDefault(false) @Override public void write(byte[] b, int off, int len) throws IOException { this.out.write(b, off, len); if (this.byteFilterIOException != null) { // Wrap because the byteFilterIOException comes from a different thread, and we want to document the call // stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterIOException); } if (this.byteFilterRuntimeException != null) { // Wrap because the byteFilterRuntimeException comes from a different thread, and we want to document the // call stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterRuntimeException); } }
@NotNullByDefault(false) @Override public void write(char[] b, int off, int len) throws IOException { this.out.write(b, off, len); if (this.charFilterIOException != null) { // Wrap because the charFilterIOException comes from a different thread, and we want to document the call // stack of THIS thread as well. throw ExceptionUtil.wrap("CharFilterReader", this.charFilterIOException); } if (this.charFilterRuntimeException != null) { // Wrap because the charFilterRuntimeException comes from a different thread, and we want to document the // call stack of THIS thread as well. throw ExceptionUtil.wrap("CharFilterReader", this.charFilterRuntimeException); } }
@NotNullByDefault(false) @Override public int read(byte[] b, int off, int len) throws IOException { final int n = this.in.read(b, off, len); if (this.byteFilterIOException != null) { // Wrap because the byteFilterIOException comes from a different thread, and we want to document the call // stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterIOException); } if (this.byteFilterRuntimeException != null) { // Wrap because the byteFilterRuntimeException comes from a different thread, and we want to document the // call stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterRuntimeException); } return n; }
@NotNullByDefault(false) @Override public int read(byte[] b, int off, int len) throws IOException { final int n = this.in.read(b, off, len); if (this.byteFilterIOException != null) { // Wrap because the byteFileIOException comes from a different thread, and we want to document the call // stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterIOException); } if (this.byteFilterRuntimeException != null) { // Wrap because the byteFilterRuntimeException comes from a different thread, and we want to document the // call stack of THIS thread as well. throw ExceptionUtil.wrap("ByteFilterInputStream", this.byteFilterRuntimeException); } return n; }
@NotNullByDefault(false) @Override public int read(char[] b, int off, int len) throws IOException { final int n = this.in.read(b, off, len); if (this.charFilterIOException != null) { // Wrap because the charFilterIOException comes from a different thread, and we want to document the call // stack of THIS thread as well. throw ExceptionUtil.wrap("CharFilterReader", this.charFilterIOException); } if (this.charFilterRuntimeException != null) { // Wrap because the charFilterRuntimeException comes from a different thread, and we want to document the // call stack of THIS thread as well. throw ExceptionUtil.wrap("CharFilterReader", this.charFilterRuntimeException); } return n; }
/** * @return All available implementations of the <var>service</var>, not cached * @throws ServiceConfigurationError Some of the services are badly configured */ public <S> Iterable<S> reload(Class<S> service) throws ServiceConfigurationError { Iterable<S> result; try { result = this.load2(service); } catch (ServiceConfigurationError sce) { throw ExceptionUtil.wrap("Service " + service, sce); } catch (Exception e) { throw ExceptionUtil.wrap("Service " + service, e, ServiceConfigurationError.class); } synchronized (this.cache) { this.cache.put(service, result); } return result; }
@Override public void run() { try { InputStream is = new FileInputStream(TextArea.this.defaultFile); try { jTextArea.read(new InputStreamReader(is, TextArea.this.encoding), null); is.close(); } finally { try { is.close(); } catch (Exception e) {} } } catch (IOException ioe) { throw ExceptionUtil.wrap( "Reading default file '" + TextArea.this.defaultFile + "'", ioe, BuildException.class ); } } });
@Override public synchronized void store() throws IOException { if (this.destroyed) throw new IllegalStateException(); if (!this.dirty) return; File newFile = new File(propertiesFile.getParentFile(), "." + propertiesFile.getName() + ",new"); OutputStream os = new FileOutputStream(newFile); try { properties.store(os, comments); os.close(); } catch (IOException ioe) { try { os.close(); } catch (Exception e) {} try { newFile.delete(); } catch (Exception e) {} throw ExceptionUtil.wrap("Creating temporary properties file", ioe); } finally { try { os.close(); } catch (Exception e) {} } File origFile = new File(propertiesFile.getParentFile(), "." + propertiesFile.getName() + ",orig"); if (origFile.exists()) PasswordAuthenticationStores.delete(origFile); if (propertiesFile.exists()) { PasswordAuthenticationStores.rename(propertiesFile, origFile); PasswordAuthenticationStores.rename(newFile, propertiesFile); PasswordAuthenticationStores.delete(origFile); } else { PasswordAuthenticationStores.rename(newFile, propertiesFile); } this.dirty = false; }
private static Object instantiateClass(Class<?> clasS, List<Object> argumentValues) throws EvaluationException { try { // Find most specific constructor. Constructor<?> mostSpecificConstructor = ReflectUtil.getMostSpecificConstructor( clasS, ReflectUtil.getTypes(argumentValues) ); // Create instance. return mostSpecificConstructor.newInstance(argumentValues.toArray()); } catch (Exception e) { throw ExceptionUtil.wrap("Instantiating " + clasS, e, EvaluationException.class); } }
@Override public void run() { if (TextArea.this.property != null) { swingDialogTask.getProject().setProperty(TextArea.this.property, jTextArea.getText()); } if (TextArea.this.file != null) { try { OutputStream os = new FileOutputStream(TextArea.this.file, TextArea.this.append); try { jTextArea.write(new OutputStreamWriter(os, TextArea.this.encoding)); os.close(); } finally { try { os.close(); } catch (Exception e) {} } } catch (IOException ioe) { throw ExceptionUtil.wrap( "Writing file '" + TextArea.this.file + "'", ioe, BuildException.class ); } } } });
/** * @return The parsed expression */ public T parse() throws ParseException, E { try { final T result = this.parseExpression().toValue(); this.eoi(); return result; } catch (ParseException pe) { throw ExceptionUtil.wrap("At " + this.scanner.toString(), pe); } catch (RuntimeException re) { throw ExceptionUtil.wrap("At " + this.scanner.toString(), re); } catch (Exception e) { @SuppressWarnings("unchecked") E ee = (E) e; throw ExceptionUtil.wrap("At " + this.scanner.toString(), ee); } }
@Override public HttpResponse put(HttpRequest httpRequest, ConsumerWhichThrows<HttpResponse, IOException> sendProvisionalResponse) throws IOException { File file = this.getFile(httpRequest); try { file = file.getCanonicalFile(); } catch (IOException ioe) { throw ExceptionUtil.wrap(file.toString(), ioe); } if (LOGGER.isLoggable(FINE)) LOGGER.fine("Accessing file '" + file + "'"); // Handle file. if (file.isFile() || !file.exists()) { OutputStream os = new FileOutputStream(file); try { httpRequest.removeBody().write(os); os.close(); } finally { try { os.close(); } catch (Exception e) {} } return HttpResponse.response(Status.OK); } // Give up. return HttpResponse.response( Status.NOT_FOUND, "Sorry - resource '" + httpRequest.getUri().getPath() + "' does not exist on this server." ); }
/** * @param <T> {@link #handleNormalContents(InputStream)} returns a value of this type, * which is, in turn, returned by the {@code processStream()} and {@code * processValue()} methods * @see #handleNormalContents(InputStream) */ public interface NormalContentsHandler<T> { /** * May or may not read from the <var>inputStream</var>, and may or may not close it. * * @see #processFile(File, Predicate, ArchiveHandler, Predicate, CompressorHandler, NormalContentsHandler) * @see CompressUtil#processStream(InputStream, Predicate, ArchiveHandler, Predicate, CompressorHandler, * NormalContentsHandler) */ @Nullable T handleNormalContents(InputStream inputStream) throws IOException; }
/** * @param <T> {@link #handleNormalContents(InputStream)} returns a value of this type, * which is, in turn, returned by the {@code processStream()} and {@code * processValue()} methods * @see #handleNormalContents(InputStream) */ public interface NormalContentsHandler<T> { /** * May or may not read from the {@code inputStream}, and may or may not close it. * * @see #processFile(File, Predicate, ArchiveHandler, Predicate, CompressorHandler, NormalContentsHandler) * @see CompressUtil#processStream(InputStream, Predicate, ArchiveHandler, Predicate, CompressorHandler, * NormalContentsHandler) */ @Nullable T handleNormalContents(InputStream inputStream) throws IOException; }