@Override public OutputStream create(String url) throws IOException { return this.create(url, false); }
@Override public boolean delete(String url, boolean isRecursiveDelete) throws IOException { try { final File file = toFile(url); if (!isRecursiveDelete && file.isDirectory()) return false; return this.delete(file); } catch (URISyntaxException e) { throw new IOException("Cannot access file.", e); } }
@Override public void setProperties(Configuration configuration) { configuration.load(ReflectionUtils.loadResource(RHEEM_BASIC_DEFAULTS_PROPERTIES)); final File localTempDir = LocalFileSystem.findTempDir(); if (localTempDir != null) { configuration.setProperty(TEMP_DIR_PROPERTY, LocalFileSystem.toURL(localTempDir)); } }
@Override public void setProperties(Configuration configuration) { final File localTempDir = LocalFileSystem.findTempDir(); if (localTempDir != null) { configuration.setProperty("rheem.graphchi.tempdir", localTempDir.toString()); } }
@Override public boolean isDirectory(String url) { try { return toFile(url).isDirectory(); } catch (URISyntaxException | MalformedURLException e) { logger.warn("Could not inspect directory.", e); return false; } }
/** * Create an empty file. * * @param file that should be created */ public static void touch(File file) { ensureDir(file.getParentFile()); try (FileOutputStream fos = new FileOutputStream(file)) { } catch (IOException e) { throw new RheemException(String.format("Could not create %s.", file), e); } }
); final File tempFile = new File(tempFilePath); LocalFileSystem.touch(tempFile); tempFile.deleteOnExit(); String graphName = tempFile.toString();
@Override public InputStream open(String url) throws IOException { try { File file = toFile(url); return new FileInputStream(file); } catch (URISyntaxException e) { throw new IOException("Could not process the given URL.", e); } }
@Override public long getFileSize(String fileUrl) throws FileNotFoundException { try { File file = toFile(fileUrl); return file.length(); } catch (MalformedURLException | URISyntaxException e) { logger.error("Illegal URL: \"{}\"", fileUrl); throw new FileNotFoundException("File not found, because the URL is not correct."); } }
private static File toFile(String fileUrl) throws URISyntaxException, MalformedURLException { if (fileUrl.startsWith("file:")) { return new File(new URL(fileUrl).toURI()); } else { logger.warn("Expect URLs, but got {}. Converting it to file:{}...", fileUrl, fileUrl); return toFile("file:" + fileUrl); } }
@Override public Collection<String> listChildren(String url) { try { final File[] files = toFile(url).listFiles(); if (files == null) { return Collections.emptyList(); } return Arrays.stream(files).map(File::toURI).map(Object::toString).collect(Collectors.toList()); } catch (URISyntaxException | MalformedURLException e) { logger.warn("Could not inspect directory.", e); return Collections.emptyList(); } }
@Override public OutputStream create(String url, Boolean forceCreateParentDirs) throws IOException { File file = null; try { file = toFile(url); if (forceCreateParentDirs && file.getParentFile()!=null) file.getParentFile().mkdirs(); return new FileOutputStream(file, false); } catch (URISyntaxException e) { throw new IOException("Could not process the given URL.", e); } catch (IOException e) { if (file != null) { file.delete(); } throw e; } }