Java Code Examples for java.io.UncheckedIOException#getCause()
The following examples show how to use
java.io.UncheckedIOException#getCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void validateFileSystemLoopException(Path start, Path... causes) { try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause(); if (ioe instanceof FileSystemLoopException) { FileSystemLoopException fsle = (FileSystemLoopException) ioe; boolean match = false; for (Path cause: causes) { if (fsle.getFile().equals(cause.toString())) { match = true; break; } } assertTrue(match); } else { fail("Unexpected UncheckedIOException cause " + ioe.toString()); } } } catch(IOException ex) { fail("Unexpected IOException " + ex); } }
Example 2
Source File: IPAddressUtil.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Returns a scoped version of the supplied local, link-local ipv6 address * if that scope-id can be determined from local NetworkInterfaces. * If the address already has a scope-id or if the address is not local, ipv6 * or link local, then the original address is returned. * * @param addr * @exception SocketException if the given ipv6 link local address is found * on more than one local interface * @return */ public static InetAddress toScopedAddress(InetAddress address) throws SocketException { if (address instanceof Inet6Address && address.isLinkLocalAddress() && ((Inet6Address) address).getScopeId() == 0) { InetAddress cached = null; try { cached = cache.computeIfAbsent(address, k -> findScopedAddress(k)); } catch (UncheckedIOException e) { throw (SocketException)e.getCause(); } return cached != null ? cached : address; } else { return address; } }
Example 3
Source File: ZipFile.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Closes the ZIP file. * * <p> Closing this ZIP file will close all of the input streams * previously returned by invocations of the {@link #getInputStream * getInputStream} method. * * @throws IOException if an I/O error has occurred */ public void close() throws IOException { if (closeRequested) { return; } closeRequested = true; synchronized (this) { // Close streams, release their inflaters, release cached inflaters // and release zip source try { res.clean(); } catch (UncheckedIOException ioe) { throw ioe.getCause(); } } }
Example 4
Source File: StreamTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void validateFileSystemLoopException(Path start, Path... causes) { try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause(); if (ioe instanceof FileSystemLoopException) { FileSystemLoopException fsle = (FileSystemLoopException) ioe; boolean match = false; for (Path cause: causes) { if (fsle.getFile().equals(cause.toString())) { match = true; break; } } assertTrue(match); } else { fail("Unexpected UncheckedIOException cause " + ioe.toString()); } } } catch(IOException ex) { fail("Unexpected IOException " + ex); } }
Example 5
Source File: JdbcExecutor.java From rheem with Apache License 2.0 | 6 votes |
private void saveResult(FileChannel.Instance outputFileChannelInstance, ResultSet rs) throws IOException, SQLException { // Output results. final FileSystem outFs = FileSystems.getFileSystem(outputFileChannelInstance.getSinglePath()).get(); try (final OutputStreamWriter writer = new OutputStreamWriter(outFs.create(outputFileChannelInstance.getSinglePath()))) { while (rs.next()) { //System.out.println(rs.getInt(1) + " " + rs.getString(2)); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { writer.write(rs.getString(i)); if (i < rsmd.getColumnCount()) { writer.write('\t'); } } if (!rs.isLast()) { writer.write('\n'); } } } catch (UncheckedIOException e) { throw e.getCause(); } }
Example 6
Source File: CloseableRemoteIterator.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T next() throws IOException { try { return iterator.next(); } catch (UncheckedIOException e) { throw e.getCause(); } }
Example 7
Source File: PagesResponseWriter.java From presto with Apache License 2.0 | 5 votes |
@Override public void writeTo(List<SerializedPage> serializedPages, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream output) throws IOException, WebApplicationException { try { SliceOutput sliceOutput = new OutputStreamSliceOutput(output); sliceOutput.writeInt(SERIALIZED_PAGES_MAGIC); sliceOutput.writeLong(dataIntegrityVerificationEnabled ? calculateChecksum(serializedPages) : NO_CHECKSUM); sliceOutput.writeInt(serializedPages.size()); writeSerializedPages(sliceOutput, serializedPages); // We use flush instead of close, because the underlying stream would be closed and that is not allowed. sliceOutput.flush(); } catch (UncheckedIOException e) { // EOF exception occurs when the client disconnects while writing data // This is not a "server" problem so we don't want to log this if (!(e.getCause() instanceof EOFException)) { throw e; } } }
Example 8
Source File: ImageReaderFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns an {@code ImageReader} to read from the given image file */ public static ImageReader get(Path jimage) throws IOException { Objects.requireNonNull(jimage); try { return readers.computeIfAbsent(jimage, OPENER); } catch (UncheckedIOException io) { throw io.getCause(); } }
Example 9
Source File: FileChannelImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
protected void implCloseChannel() throws IOException { if (!fd.valid()) return; // nothing to do // Release and invalidate any locks that we still hold if (fileLockTable != null) { for (FileLock fl: fileLockTable.removeAll()) { synchronized (fl) { if (fl.isValid()) { nd.release(fd, fl.position(), fl.size()); ((FileLockImpl)fl).invalidate(); } } } } // signal any threads blocked on this channel threads.signalAndWait(); if (parent != null) { // Close the fd via the parent stream's close method. The parent // will reinvoke our close method, which is defined in the // superclass AbstractInterruptibleChannel, but the isOpen logic in // that method will prevent this method from being reinvoked. // ((java.io.Closeable)parent).close(); } else if (closer != null) { // Perform the cleaning action so it is not redone when // this channel becomes phantom reachable. try { closer.clean(); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } } else { fdAccess.close(fd); } }
Example 10
Source File: ImageReaderFactory.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns an {@code ImageReader} to read from the given image file */ public static ImageReader get(Path jimage) throws IOException { Objects.requireNonNull(jimage); try { return readers.computeIfAbsent(jimage, OPENER); } catch (UncheckedIOException io) { throw io.getCause(); } }
Example 11
Source File: StreamTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void checkMalformedInputException(Stream<String> s) { try { List<String> lines = s.collect(Collectors.toList()); fail("UncheckedIOException expected"); } catch (UncheckedIOException ex) { IOException cause = ex.getCause(); assertTrue(cause instanceof MalformedInputException, "MalformedInputException expected"); } }
Example 12
Source File: StreamTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void checkMalformedInputException(Stream<String> s) { try { List<String> lines = s.collect(Collectors.toList()); fail("UncheckedIOException expected"); } catch (UncheckedIOException ex) { IOException cause = ex.getCause(); assertTrue(cause instanceof MalformedInputException, "MalformedInputException expected"); } }
Example 13
Source File: FileDirs.java From loom-fiber with MIT License | 5 votes |
private static long lineCount(Path directory, Predicate<? super Path> filter, int limit) throws IOException { try(var files = walk(directory)) { return files .filter(not(Files::isDirectory)) .filter(filter) .limit(limit) .map(path -> async(() -> lineCountFile(path))) .collect(toList()) .stream() .mapToLong(Task::join) .sum(); } catch(UncheckedIOException e) { throw e.getCause(); } }
Example 14
Source File: StreamTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void checkMalformedInputException(Stream<String> s) { try { List<String> lines = s.collect(Collectors.toList()); fail("UncheckedIOException expected"); } catch (UncheckedIOException ex) { IOException cause = ex.getCause(); assertTrue(cause instanceof MalformedInputException, "MalformedInputException expected"); } }
Example 15
Source File: CloseableRemoteIterator.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override // idempotent public void close() throws IOException { if (!closed.compareAndSet(false, true)) { return; } try { stream.close(); } catch (UncheckedIOException e) { throw e.getCause(); } }
Example 16
Source File: HashUtil.java From Stark with Apache License 2.0 | 5 votes |
public static HashValue createHash(File file, String algorithm) { try { return createHash((InputStream) (new FileInputStream(file)), algorithm); } catch (UncheckedIOException var3) { throw new UncheckedIOException(String.format("Failed to create %s hash for file %s.", algorithm, file.getAbsolutePath()), var3.getCause()); } catch (FileNotFoundException var4) { throw new UncheckedIOException(var4); } }
Example 17
Source File: FileMonitor.java From rheem with Apache License 2.0 | 5 votes |
@Override public void initialize(Configuration config, String runId, List<Map> initialExecutionPlan) throws IOException { this.initialExecutionPlan = initialExecutionPlan; this.runId = runId; String runsDir = config.getStringProperty(DEFAULT_MONITOR_BASE_URL_PROPERTY_KEY, DEFAULT_MONITOR_BASE_URL); final String path = runsDir + "/" + runId; this.exPlanUrl = path + "/execplan.json"; this.progressUrl = path + "/progress.json"; final FileSystem execplanFile = FileSystems.getFileSystem(exPlanUrl).get(); try (final OutputStreamWriter writer = new OutputStreamWriter(execplanFile.create(exPlanUrl, true))) { HashMap<String, Object> jsonPlanMap = new HashMap<>(); jsonPlanMap.put("stages", initialExecutionPlan); jsonPlanMap.put("run_id", runId); JSONObject jsonPlan = new JSONObject(jsonPlanMap); writer.write(jsonPlan.toString()); } catch (UncheckedIOException e) { throw e.getCause(); } HashMap<String, Integer> initialProgress = new HashMap<>(); for (Map stage: initialExecutionPlan) { for (Map operator: (List<Map>)stage.get("operators")) { initialProgress.put((String)operator.get("name"), 0); } } updateProgress(initialProgress); }
Example 18
Source File: StreamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void checkMalformedInputException(Stream<String> s) { try { List<String> lines = s.collect(Collectors.toList()); fail("UncheckedIOException expected"); } catch (UncheckedIOException ex) { IOException cause = ex.getCause(); assertTrue(cause instanceof MalformedInputException, "MalformedInputException expected"); } }
Example 19
Source File: StreamTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void checkMalformedInputException(Stream<String> s) { try { List<String> lines = s.collect(Collectors.toList()); fail("UncheckedIOException expected"); } catch (UncheckedIOException ex) { IOException cause = ex.getCause(); assertTrue(cause instanceof MalformedInputException, "MalformedInputException expected"); } }
Example 20
Source File: JMXConnectorFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Creates a connector from a provider loaded from the ServiceLoader. * <p> * The pair (P,C) will be either one of: <br> * a. (JMXConnectorProvider, JMXConnector) or <br> * b. (JMXConnectorServerProvider, JMXConnectorServer) * * @param providerClass The service type for which an implementation * should be looked up from the {@code ServiceLoader}. This will * be either {@code JMXConnectorProvider.class} or * {@code JMXConnectorServerProvider.class} * * @param loader The ClassLoader to use when looking up an implementation * of the service. If null, then only installed services will be * considered. * * @param url The JMXServiceURL of the connector for which a provider is * requested. * * @param filter A filter used to exclude or return provider * implementations. Typically the filter will either exclude * system services (system default implementations) or only * retain those. * This can allow to first look for custom implementations (e.g. * deployed on the CLASSPATH with META-INF/services) and * then only default to system implementations. * * @param factory A functional factory that can attempt to create an * instance of connector {@code C} from a provider {@code P}. * Typically, this is a simple wrapper over {@code * JMXConnectorProvider::newJMXConnector} or {@code * JMXConnectorProviderServer::newJMXConnectorServer}. * * @throws IOException if {@code C} could not be instantiated, and * at least one provider {@code P} threw an exception that wasn't a * {@code MalformedURLException} or a {@code JMProviderException}. * * @throws JMXProviderException if a provider {@code P} for the protocol in * <code>url</code> was found, but couldn't create the connector * {@code C} for some reason. * * @return an instance of {@code C} if a provider {@code P} was found from * which one could be instantiated, {@code null} otherwise. */ static <P,C> C getConnectorAsService(Class<P> providerClass, ClassLoader loader, JMXServiceURL url, Predicate<Provider<?>> filter, ConnectorFactory<P,C> factory) throws IOException { // sanity check if (JMXConnectorProvider.class != providerClass && JMXConnectorServerProvider.class != providerClass) { // should never happen throw new InternalError("Unsupported service interface: " + providerClass.getName()); } ServiceLoader<P> serviceLoader = loader == null ? ServiceLoader.loadInstalled(providerClass) : ServiceLoader.load(providerClass, loader); Stream<Provider<P>> stream = serviceLoader.stream().filter(filter); ProviderFinder<P,C> finder = new ProviderFinder<>(factory, url); try { stream.filter(finder).findFirst(); return finder.get(); } catch (UncheckedIOException e) { if (e.getCause() instanceof JMXProviderException) { throw (JMXProviderException) e.getCause(); } else { throw e; } } }