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); } }
ExceptionUtil.<RuntimeException>throwUndeclared2(e);
@Override public Object get(@Nullable Object key) { return ( "name".equals(key) ? record.getLoggerName() : "level".equals(key) ? record.getLevel().getName() : "class".equals(key) ? record.getSourceClassName() : "method".equals(key) ? record.getSourceMethodName() : "message".equals(key) ? record.getMessage() : "params".equals(key) ? record.getParameters() : ExceptionUtil.throW(new IllegalStateException("Value of variable '" + key + "' missing")) ); } };
/** * Converts the given {@code subject} to the given primitive target type. Special processing applies for target * type {@code boolean.class}, see {@link #toBoolean(Object)}. * * @throws EvaluationException The {@code subject} is {@code null} (and the {@code targetType} is not {@code * boolean.class}) * @throws EvaluationException The {@code subject} cannot be converted to the given {@code targetType} */ @SuppressWarnings("unchecked") public static <T> T toPrimitive(@Nullable Object subject, Class<T> targetType) throws EvaluationException { if (!targetType.isPrimitive()) throw new AssertionError(targetType); if (targetType == boolean.class) return (T) Boolean.valueOf(ExpressionEvaluator.toBoolean(subject)); if (subject == null) { throw new EvaluationException("Cannot convert 'null' to '" + targetType.getName() + "'"); } Class<?> wrapperType = ( targetType == char.class ? Character.class : targetType == byte.class ? Byte.class : targetType == short.class ? Short.class : targetType == int.class ? Integer.class : targetType == long.class ? Long.class : targetType == float.class ? Float.class : targetType == double.class ? Double.class : ExceptionUtil.<Class<?>>throwAssertionError(targetType) ); if (subject.getClass() != wrapperType) { throw new EvaluationException("Cannot convert '" + subject.getClass() + "' to '" + targetType + "'"); } return (T) subject; }
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); } }
ExceptionUtil.<RuntimeException>throwUndeclared2(e);
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 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(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(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; }