use of java.nio.file.ProviderNotFoundException in project j2objc by google.
the class FileSystemsTest method test_newFileSystem$URI$Map.
@Test
public void test_newFileSystem$URI$Map() throws IOException {
Path testPath = Paths.get("/");
Map<String, String> stubEnv = new HashMap<>();
try {
FileSystems.newFileSystem(testPath.toUri(), stubEnv);
fail();
} catch (FileSystemAlreadyExistsException expected) {
}
try {
FileSystems.newFileSystem(null, stubEnv);
fail();
} catch (NullPointerException expected) {
}
try {
FileSystems.newFileSystem(testPath, null);
fail();
} catch (ProviderNotFoundException expected) {
}
}
use of java.nio.file.ProviderNotFoundException in project j2objc by google.
the class ProviderNotFoundExceptionTest method test_constructor$String.
public void test_constructor$String() {
String message = "message";
ProviderNotFoundException exception = new ProviderNotFoundException(message);
assertEquals(message, exception.getMessage());
message = null;
exception = new ProviderNotFoundException(message);
assertEquals(message, exception.getMessage());
}
use of java.nio.file.ProviderNotFoundException in project alien4cloud by alien4cloud.
the class ToscaArchiveParser method parseImports.
@ToscaContextual(requiresNew = true)
public ParsingResult<CsarDependenciesBean> parseImports(Path archiveFile) throws ParsingException {
try (FileSystem csarFS = FileSystems.newFileSystem(archiveFile, null)) {
if (Files.exists(csarFS.getPath(TOSCA_META_FILE_LOCATION))) {
YamlSimpleParser<ToscaMeta> parser = new YamlSimpleParser<ToscaMeta>(toscaMetaMapping.getParser());
ParsingResult<ToscaMeta> parsingResult = parser.parseFile(csarFS.getPath(TOSCA_META_FILE_LOCATION));
CsarDependenciesBean csarDependenciesBean = initDependencyBeanFromToscaMeta(parsingResult.getResult());
return parseFromToscaMeta(csarFS, parsingResult.getResult(), TOSCA_META_FILE_LOCATION, csarDependenciesBean, toscaImportParser);
}
return parseFromRootDefinitions(csarFS, toscaImportParser);
} catch (IOException e) {
log.error("Unable to read uploaded archive [" + archiveFile + "]", e);
throw new ParsingException("Archive", new ParsingError(ErrorCode.FAILED_TO_READ_FILE, "Problem happened while accessing file", null, null, null, archiveFile.toString()));
} catch (ProviderNotFoundException e) {
log.warn("Failed to import archive", e);
throw new ParsingException("Archive", new ParsingError(ErrorCode.ERRONEOUS_ARCHIVE_FILE, "File is not in good format, only zip file is supported ", null, e.getMessage(), null, null));
}
}
use of java.nio.file.ProviderNotFoundException in project beam by apache.
the class JavaUdfLoader method loadJar.
private FunctionDefinitions loadJar(String jarPath) throws IOException {
if (functionCache.containsKey(jarPath)) {
LOG.debug("Using cached function definitions from {}", jarPath);
return functionCache.get(jarPath);
}
ClassLoader classLoader = createClassLoader(jarPath);
Map<List<String>, ScalarFn> scalarFunctions = new HashMap<>();
Map<List<String>, AggregateFn> aggregateFunctions = new HashMap<>();
Iterator<UdfProvider> providers = getUdfProviders(classLoader);
int providersCount = 0;
while (providers.hasNext()) {
providersCount++;
UdfProvider provider = providers.next();
provider.userDefinedScalarFunctions().forEach((functionName, implementation) -> {
List<String> functionPath = ImmutableList.copyOf(functionName.split("\\."));
if (scalarFunctions.containsKey(functionPath)) {
throw new IllegalArgumentException(String.format("Found multiple definitions of scalar function %s in %s.", functionName, jarPath));
}
scalarFunctions.put(functionPath, implementation);
});
provider.userDefinedAggregateFunctions().forEach((functionName, implementation) -> {
List<String> functionPath = ImmutableList.copyOf(functionName.split("\\."));
if (aggregateFunctions.containsKey(functionPath)) {
throw new IllegalArgumentException(String.format("Found multiple definitions of aggregate function %s in %s.", functionName, jarPath));
}
aggregateFunctions.put(functionPath, implementation);
});
}
if (providersCount == 0) {
throw new ProviderNotFoundException(String.format("No %s implementation found in %s. Create a class implementing %s and annotate it with @AutoService(%s.class).", UdfProvider.class.getSimpleName(), jarPath, UdfProvider.class.getSimpleName(), UdfProvider.class.getSimpleName()));
}
LOG.info("Loaded {} implementations of {} from {} with {} scalar function(s).", providersCount, UdfProvider.class.getSimpleName(), jarPath, scalarFunctions.size());
FunctionDefinitions userFunctionDefinitions = FunctionDefinitions.newBuilder().setScalarFunctions(ImmutableMap.copyOf(scalarFunctions)).setAggregateFunctions(ImmutableMap.copyOf(aggregateFunctions)).build();
functionCache.put(jarPath, userFunctionDefinitions);
return userFunctionDefinitions;
}
use of java.nio.file.ProviderNotFoundException in project j2objc by google.
the class FileSystemsTest method test_newFileSystem$Path$ClassLoader.
/* J2ObjC removed: PathClassLoader unsupported
@Test
public void test_newFileSystem$URI$Map$ClassLoader_customClassLoader() throws Exception {
Map<String, String> stubEnv = new HashMap<>();
// Verify that the Thread's classloader cannot load mypackage.MockFileSystem.
try {
Thread.currentThread().getContextClassLoader().loadClass("mypackage.MockFileSystem");
fail();
} catch (ClassNotFoundException expected) {}
ClassLoader fileSystemsClassLoader = createClassLoaderForTestFileSystems();
// The file system configured in filesystemstest.jar is for scheme "stubScheme://
URI stubURI = new URI("stubScheme://sometext");
FileSystem fs = FileSystems.newFileSystem(stubURI, stubEnv, fileSystemsClassLoader);
assertEquals("mypackage.MockFileSystem", fs.getClass().getName());
assertSame(stubURI, fs.getClass().getDeclaredMethod("getURI").invoke(fs));
assertSame(stubEnv, fs.getClass().getDeclaredMethod("getEnv").invoke(fs));
}
*/
@Test
public void test_newFileSystem$Path$ClassLoader() throws Exception {
Path testPath = Paths.get("/");
try {
FileSystems.newFileSystem(testPath, Thread.currentThread().getContextClassLoader());
fail();
} catch (ProviderNotFoundException expected) {
}
try {
FileSystems.newFileSystem(null, Thread.currentThread().getContextClassLoader());
fail();
} catch (NullPointerException expected) {
}
try {
FileSystems.newFileSystem(testPath, null);
fail();
} catch (ProviderNotFoundException expected) {
}
}
Aggregations