[ 
https://issues.apache.org/jira/browse/BEAM-9577?focusedWorklogId=433399&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-433399
 ]

ASF GitHub Bot logged work on BEAM-9577:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/May/20 22:19
            Start Date: 14/May/20 22:19
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on a change in pull request #11708:
URL: https://github.com/apache/beam/pull/11708#discussion_r425462830



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/io/ClassLoaderFileSystem.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.service.AutoService;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.io.fs.CreateOptions;
+import org.apache.beam.sdk.io.fs.MatchResult;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.sdk.options.PipelineOptions;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+
+/** A read-only {@link FileSystem} implementation looking up resources using a 
ClassLoader. */
+public class ClassLoaderFileSystem extends 
FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId> {
+
+  public static final String SCHEMA = "classpath";
+  private static final String PREFIX = SCHEMA + "://";
+
+  ClassLoaderFileSystem() {}
+
+  @Override
+  protected List<MatchResult> match(List<String> specs) throws IOException {
+    throw new UnsupportedOperationException("Un-globable filesystem.");
+  }
+
+  @Override
+  protected WritableByteChannel create(
+      ClassLoaderResourceId resourceId, CreateOptions createOptions) throws 
IOException {
+    throw new UnsupportedOperationException("Read-only filesystem.");
+  }
+
+  @Override
+  protected ReadableByteChannel open(ClassLoaderResourceId resourceId) throws 
IOException {
+    ClassLoader classLoader = getClass().getClassLoader();
+    InputStream inputStream =
+        
classLoader.getResourceAsStream(resourceId.path.substring(PREFIX.length()));
+    if (inputStream == null) {
+      throw new IOException("Unable to load " + resourceId.path + " with " + 
classLoader);
+    }
+    return Channels.newChannel(inputStream);
+  }
+
+  @Override
+  protected void copy(
+      List<ClassLoaderResourceId> srcResourceIds, List<ClassLoaderResourceId> 
destResourceIds)
+      throws IOException {
+    throw new UnsupportedOperationException("Read-only filesystem.");
+  }
+
+  @Override
+  protected void rename(
+      List<ClassLoaderResourceId> srcResourceIds, List<ClassLoaderResourceId> 
destResourceIds)
+      throws IOException {
+    throw new UnsupportedOperationException("Read-only filesystem.");
+  }
+
+  @Override
+  protected void delete(Collection<ClassLoaderResourceId> resourceIds) throws 
IOException {
+    throw new UnsupportedOperationException("Read-only filesystem.");
+  }
+
+  @Override
+  protected ClassLoaderResourceId matchNewResource(String path, boolean 
isDirectory) {
+    return new ClassLoaderResourceId(path);
+  }
+
+  @Override
+  protected String getScheme() {
+    return SCHEMA;
+  }
+
+  public static class ClassLoaderResourceId implements ResourceId {
+
+    private final String path;
+
+    private ClassLoaderResourceId(String path) {
+      checkArgument(path.startsWith(PREFIX), path);
+      this.path = path;
+    }
+
+    @Override
+    public ResourceId resolve(String other, ResolveOptions resolveOptions) {

Review comment:
       The documentation is in the super classes, but I added a test. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 433399)
    Time Spent: 21h 40m  (was: 21.5h)

> Update artifact staging and retrieval protocols to be dependency aware.
> -----------------------------------------------------------------------
>
>                 Key: BEAM-9577
>                 URL: https://issues.apache.org/jira/browse/BEAM-9577
>             Project: Beam
>          Issue Type: Improvement
>          Components: beam-model
>            Reporter: Robert Bradshaw
>            Assignee: Robert Bradshaw
>            Priority: Major
>          Time Spent: 21h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to