private static String getSchema(String schemaPath) throws IOException { ReadableByteChannel channel = FileSystems.open(FileSystems.matchNewResource( schemaPath, false)); try (InputStream stream = Channels.newInputStream(channel)) { BufferedReader streamReader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); StringBuilder dataBuilder = new StringBuilder(); String line; while ((line = streamReader.readLine()) != null) { dataBuilder.append(line); } return dataBuilder.toString(); } }
public static String getSchema(String schemaPath) throws IOException { ReadableByteChannel chan = FileSystems.open(FileSystems.matchNewResource( schemaPath, false)); try (InputStream stream = Channels.newInputStream(chan)) { BufferedReader streamReader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); StringBuilder dataBuilder = new StringBuilder(); String line; while ((line = streamReader.readLine()) != null) { dataBuilder.append(line); } return dataBuilder.toString(); } }
@Override public ResourceId apply(String input) { return FileSystems.matchNewResource(input, true); } }
@Override public ResourceId apply(String input) { return FileSystems.matchNewResource(input, true); } }
static void removeTemporaryFiles(Iterable<String> files) throws IOException { ImmutableList.Builder<ResourceId> fileResources = ImmutableList.builder(); for (String file : files) { fileResources.add(FileSystems.matchNewResource(file, false /* isDirectory */)); } FileSystems.delete(fileResources.build()); } }
public static void writeToFile(String filename, ByteBuffer contents) throws IOException { ResourceId resourceId = FileSystems.matchNewResource(filename, false); try (WritableByteChannel out = FileSystems.create(resourceId, MimeTypes.TEXT)) { out.write(contents); } }
private static void copyToRemote(Path src, URI dst) throws IOException { ResourceId dstId = FileSystems.matchNewResource(dst.toString(), false); WritableByteChannel dstCh = FileSystems.create(dstId, MimeTypes.BINARY); FileChannel srcCh = FileChannel.open(src, StandardOpenOption.READ); long srcSize = srcCh.size(); long copied = 0; do { copied += srcCh.transferTo(copied, srcSize - copied, dstCh); } while (copied < srcSize); dstCh.close(); srcCh.close(); Preconditions.checkState(copied == srcSize); }
TableRowWriter(String basename) throws Exception { String uId = UUID.randomUUID().toString(); resourceId = FileSystems.matchNewResource(basename + uId, false); LOG.info("Opening TableRowWriter to {}.", resourceId); channel = FileSystems.create(resourceId, MimeTypes.TEXT); out = new CountingOutputStream(Channels.newOutputStream(channel)); }
@Override public ResourceId decode(InputStream is) throws IOException { String spec = STRING_CODER.decode(is); boolean isDirectory = BOOL_CODER.decode(is); return FileSystems.matchNewResource(spec, isDirectory); }
private static void writeTextToFileSideEffect(String text, String filename) throws IOException { ResourceId rid = FileSystems.matchNewResource(filename, false); WritableByteChannel chan = FileSystems.create(rid, "text/plain"); chan.write(ByteBuffer.wrap(text.getBytes(StandardCharsets.UTF_8))); chan.close(); } }
static String resolveTempLocation( String tempLocationDir, String bigQueryOperationName, String stepUuid) { return FileSystems.matchNewResource(tempLocationDir, true) .resolve(bigQueryOperationName, ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY) .resolve(stepUuid, ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY) .toString(); } }
public static FileNaming relativeFileNaming( final ValueProvider<String> baseDirectory, final FileNaming innerNaming) { return (window, pane, numShards, shardIndex, compression) -> FileSystems.matchNewResource(baseDirectory.get(), true /* isDirectory */) .resolve( innerNaming.getFilename(window, pane, numShards, shardIndex, compression), RESOLVE_FILE) .toString(); }
private ViaFileBasedSink(Write<DestinationT, UserT> spec) { super( ValueProvider.NestedValueProvider.of( spec.getTempDirectory(), input -> FileSystems.matchNewResource(input, true /* isDirectory */)), new DynamicDestinationsAdapter<>(spec), spec.getCompression()); this.spec = spec; }
@Test(expected = IllegalArgumentException.class) public void testInvalidSchemaMatchNewResource() { assertEquals("file", FileSystems.matchNewResource("invalidschema://tmp/f1", false)); assertEquals("file", FileSystems.matchNewResource("c:/tmp/f1", false)); }
@Test public void testValidMatchNewResourceForLocalFileSystem() { assertEquals("file", FileSystems.matchNewResource("/tmp/f1", false).getScheme()); assertEquals("file", FileSystems.matchNewResource("tmp/f1", false).getScheme()); assertEquals("file", FileSystems.matchNewResource("c:\\tmp\\f1", false).getScheme()); }
@Override public FileResult<DestinationT> decode(InputStream inStream) throws IOException { String tempFilename = FILENAME_CODER.decode(inStream); BoundedWindow window = windowCoder.decode(inStream); PaneInfo paneInfo = PANE_INFO_CODER.decode(inStream); int shard = SHARD_CODER.decode(inStream); DestinationT destination = destinationCoder.decode(inStream); return new FileResult<>( FileSystems.matchNewResource(tempFilename, false /* isDirectory */), shard, window, paneInfo, destination); }
TestSink(String tmpFolder) { super( ValueProvider.StaticValueProvider.of(FileSystems.matchNewResource(tmpFolder, true)), DynamicFileDestinations.constant(FILENAME_POLICY, SerializableFunctions.identity())); }
private static MatchResult.Metadata metadata(Path path, int size) { return MatchResult.Metadata.builder() .setResourceId(FileSystems.matchNewResource(path.toString(), false /* isDirectory */)) .setIsReadSeekEfficient(true) .setSizeBytes(size) .build(); }
DummySink() { super( StaticValueProvider.of(FileSystems.matchNewResource("nowhere", false)), DynamicFileDestinations.constant( new DummyFilenamePolicy(), SerializableFunctions.constant(null))); }
@Test public void testPackageUploadIsSkippedWithNonExistentResource() throws Exception { String nonExistentFile = FileSystems.matchNewResource(tmpFolder.getRoot().getPath(), true) .resolve("non-existent-file", StandardResolveOptions.RESOLVE_FILE) .toString(); assertEquals( Collections.EMPTY_LIST, defaultPackageUtil.stageClasspathElements( ImmutableList.of(nonExistentFile), STAGING_PATH, createOptions)); }