@Override public InputStream getResourceInputStream(Account account, ResourceType type, String name, int version) throws IOException { File file = getFile(account, type, name, version); if (!file.exists()) { return null; } return new FileInputStream(file); }
@Override PluginStore getInitializedStore() throws IOException { conf.set(Constants.LocalFilePluginStore.DATA_DIR, tmpFolder.newFolder().getAbsolutePath()); store.initialize(conf); return store; }
@Override public void deleteResource(Account account, ResourceType type, String name, int version) throws IOException { File file = getFile(account, type, name, version); if (file.exists()) { // TODO: delete directory structure if empty file.delete(); } }
/** * Get an output stream for the given resource. Files are namespaced by base data directory, * plugin type, plugin name, resource type, resource name, and resource version. For example, version 2 of resource * 'hadoop' of type 'cookbook'' for automator type 'chef-solo' with data directory '/var/coopr/data/plugins' will be * written to '/var/coopr/data/plugins/automatortypes/chef-solo/cookbook/hadoop/2'. * * @param account Account that owns the plugin resource * @param type Type of resource * @param name Name of the resource being written * @param version Version of the resource being written * @return Output stream for the file * @throws IOException if there was an error creating the file */ @Override public OutputStream getResourceOutputStream(Account account, ResourceType type, String name, int version) throws IOException { File file = getFile(account, type, name, version); File parent = file.getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { throw new IOException("Unable to create directory " + parent.getAbsolutePath()); } } if (!file.exists()) { if (!file.createNewFile()) { throw new IOException("Unable to create file " + file.getAbsolutePath()); } } return new FileOutputStream(file); }