Java Code Examples for java.io.IOException#getSuppressed()
The following examples show how to use
java.io.IOException#getSuppressed() .
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: TestNativeFSLockFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testBadPermissions() throws IOException { // create a mock filesystem that will throw exc on creating test.lock Path tmpDir = createTempDir(); tmpDir = FilterPath.unwrap(tmpDir).toRealPath(); FileSystem mock = new MockBadPermissionsFileSystem(tmpDir.getFileSystem()).getFileSystem(null); Path mockPath = mock.getPath(tmpDir.toString()); // we should get an IOException (typically NoSuchFileException but no guarantee) with // our fake AccessDenied added as suppressed. Directory dir = getDirectory(mockPath.resolve("indexDir")); IOException expected = expectThrows(IOException.class, () -> { dir.obtainLock("test.lock"); }); AccessDeniedException suppressed = (AccessDeniedException) expected.getSuppressed()[0]; assertTrue(suppressed.getMessage().contains("fake access denied")); dir.close(); }
Example 2
Source File: MuxLock.java From terracotta-platform with Apache License 2.0 | 6 votes |
@Override public void close() throws IOException { IOException error = new IOException("Failed to close locks"); while (true) { CloseLock lock = locks.peek(); if (lock == null) { break; } try { lock.close(); } catch (IOException e) { error.addSuppressed(e); } locks.pop(); } if (error.getSuppressed().length > 0) { throw error; } }
Example 3
Source File: FlowAdapterTest.java From java-async-util with Apache License 2.0 | 5 votes |
@Test public void testCloseErrorSuppressed() throws Throwable { try { FlowAdapterTest .consume(new ExceptionalIterator(5, new IOException(), new TimeoutException())); Assert.fail("iterator should have thrown exception"); } catch (final IOException e) { final Throwable[] arr = e.getSuppressed(); Assert.assertTrue(arr.length == 1); Assert.assertTrue(arr[0] instanceof TimeoutException); } }
Example 4
Source File: ConnectionInformationFileUtils.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** Clear the connection file cache. Will log the first occurring error and how many errors occurred in total. */ private static void clearCache() { try (Stream<Path> paths = Files.walk(getCacheLocation())) { ListenerTools.informAllAndThrow(paths.sorted(Comparator.reverseOrder()).collect(Collectors.toList()), Files::delete, IOException.class); } catch (IOException ioe) { Throwable[] suppressed = ioe.getSuppressed(); LogService.getRoot().log(Level.WARNING, "com.rapidminer.connection.file_cache.unable_to_delete", new Object[]{ioe.getMessage(), suppressed.length + 1}); } }
Example 5
Source File: LogSearch.java From JavaSCR with MIT License | 5 votes |
private static void FindLogEntryBad(String search) { // Construct regex dynamically from user string String regex = "(.*? +public\\[\\d+\\] +.*" + search + ".*)"; Pattern searchPattern = Pattern.compile(regex); try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { // Get the file's size and map it into memory long size = channel.size(); final MappedByteBuffer mappedBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); Charset charset = Charset.forName("ISO-8859-15"); final CharsetDecoder decoder = charset.newDecoder(); // Read file into char buffer CharBuffer log = decoder.decode(mappedBuffer); Matcher logMatcher = searchPattern.matcher(log); while (logMatcher.find()) { String match = logMatcher.group(); if (!match.isEmpty()) { System.out.println(match); } } } catch (IOException ex) { System.err.println("thrown exception: " + ex.toString()); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); } } }
Example 6
Source File: LogSearch.java From JavaSCR with MIT License | 5 votes |
private static void FindLogEntryQuote(String search) { // Construct regex dynamically from user string String regex = "(.*? +public\\[\\d+\\] +.*" + Pattern.quote(search) + ".*)"; Pattern searchPattern = Pattern.compile(regex); try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { // Get the file's size and map it into memory long size = channel.size(); final MappedByteBuffer mappedBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); Charset charset = Charset.forName("ISO-8859-15"); final CharsetDecoder decoder = charset.newDecoder(); // Read file into char buffer CharBuffer log = decoder.decode(mappedBuffer); Matcher logMatcher = searchPattern.matcher(log); while (logMatcher.find()) { String match = logMatcher.group(); if (!match.isEmpty()) { System.out.println(match); } } } catch (IOException ex) { System.err.println("thrown exception: " + ex.toString()); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); } } }