本文整理汇总了Java中java.io.UncheckedIOException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java UncheckedIOException.getCause方法的具体用法?Java UncheckedIOException.getCause怎么用?Java UncheckedIOException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.UncheckedIOException
的用法示例。
在下文中一共展示了UncheckedIOException.getCause方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateFileSystemLoopException
import java.io.UncheckedIOException; //导入方法依赖的package包/类
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);
}
}
示例2: resolvePaths
import java.io.UncheckedIOException; //导入方法依赖的package包/类
private static List<Path> resolvePaths(List<Path> inputDirs, List<InputFile> inputFiles) throws IOException {
List<Path> ret = new ArrayList<>(inputFiles.size());
for (InputFile inputFile : inputFiles) {
boolean found = false;
for (Path inputDir : inputDirs) {
try (Stream<Path> matches = Files.find(inputDir, Integer.MAX_VALUE, (path, attr) -> inputFile.equals(path), FileVisitOption.FOLLOW_LINKS)) {
Path file = matches.findFirst().orElse(null);
if (file != null) {
ret.add(file);
found = true;
break;
}
} catch (UncheckedIOException e) {
throw e.getCause();
}
}
if (!found) throw new IOException("can't find input "+inputFile.getFileName());
}
return ret;
}
示例3: runDatabaseMigration
import java.io.UncheckedIOException; //导入方法依赖的package包/类
public void runDatabaseMigration() throws IOException {
final ScriptOperations scriptOps = mongoTemplate.scriptOps();
if (migrationProperties.getScriptHome() != null) {
try {
Files.list(migrationProperties.getScriptHome())
.filter(s -> migrationProperties.getPattern().matcher(s.getFileName().toString()).find())
.sorted(this::compareCaseInsensitive)
.forEachOrdered(s -> runDatabaseMigration(s, scriptOps));
} catch (UncheckedIOException ex) {
throw ex.getCause();
}
} else {
log.error("smarti.migration.mongo.script-home not set - not running database migration!");
}
}
示例4: readEnigma
import java.io.UncheckedIOException; //导入方法依赖的package包/类
public static void readEnigma(Path dir, IMappingAcceptor mappingAcceptor) throws IOException {
try (Stream<Path> stream = Files.find(dir,
Integer.MAX_VALUE,
(path, attr) -> attr.isRegularFile() && path.getFileName().toString().endsWith(".mapping"),
FileVisitOption.FOLLOW_LINKS)) {
stream.forEach(file -> readEnigmaFile(file, mappingAcceptor));
} catch (UncheckedIOException e) {
throw e.getCause();
}
}
示例5: deleteRecursive
import java.io.UncheckedIOException; //导入方法依赖的package包/类
/**
* Deletes folder and its contents recursively. FOLLOWS SYMLINKS!
*/
public static void deleteRecursive(Path f) throws IOException {
if (Files.isDirectory(f)) {
try (Stream<Path> stream = Files.list(f)){
for (Path sub : (Iterable<Path>) stream::iterator) {
deleteRecursive(sub);
}
} catch (UncheckedIOException wrapEx) {
throw wrapEx.getCause();
}
}
FileUtils.removeReadOnly(f);
}
示例6: checkMalformedInputException
import java.io.UncheckedIOException; //导入方法依赖的package包/类
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");
}
}
示例7: get
import java.io.UncheckedIOException; //导入方法依赖的package包/类
/**
* 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();
}
}
示例8: open
import java.io.UncheckedIOException; //导入方法依赖的package包/类
@Override
public ModuleReader open() throws IOException {
try {
return readerSupplier.get();
} catch (UncheckedIOException e) {
throw e.getCause();
}
}
示例9: forEachLine
import java.io.UncheckedIOException; //导入方法依赖的package包/类
/**
* Reads all lines of text from this source, running the given {@code action} for each line as
* it is read.
*
* <p>Like {@link BufferedReader#readLine()}, this method considers a line to be a sequence of
* text that is terminated by (but does not include) one of {@code \r\n}, {@code \r} or
* {@code \n}. If the source's content does not end in a line termination sequence, it is treated
* as if it does.
*
* @throws IOException if an I/O error occurs while reading from this source or if
* {@code action} throws an {@code UncheckedIOException}
* @since 22.0
*/
@Beta
public void forEachLine(Consumer<? super String> action) throws IOException {
try (Stream<String> lines = lines()) {
// The lines should be ordered regardless in most cases, but use forEachOrdered to be sure
lines.forEachOrdered(action);
} catch (UncheckedIOException e) {
throw e.getCause();
}
}
示例10: getConnectorAsService
import java.io.UncheckedIOException; //导入方法依赖的package包/类
/**
* 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;
}
}
}