All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.agent.ProcessStore Maven / Gradle / Ivy

package org.snapscript.agent;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

import org.snapscript.common.store.RemoteStore;
import org.snapscript.common.store.Store;

public class ProcessStore implements Store {

   private String project;
   private Store store;
   
   public ProcessStore(URI root) {
      this.store = new RemoteStore(root);
   }
   
   public void update(String project) {
      this.project = project;
   }

   @Override
   public InputStream getInputStream(String resource) {
      String path = getPath(project, resource);
      return store.getInputStream(path);
   }
   
   @Override
   public OutputStream getOutputStream(String resource) {
      String path = getPath(project, resource);
      return store.getOutputStream(path);
   }
   
   public static String getPath(String project, String resource) {
      if(project != null) {
         if(!project.startsWith("/")) {
            project = "/" + project;
         }
         if(!project.endsWith("/")) {
            project = project + "/";
         }
         if(resource.startsWith("/")) {
            resource = resource.substring(1);
         }
         return project.concat(resource).replace("//", "/");
      }
      return resource.replace("//", "/");
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy