@@ -181,6 +181,32 @@ public static File getResource(URL url, boolean install) throws Exception {
181181 return resource ;
182182 }
183183
184+ /**
185+ * Get a local representation of the remote resource.
186+ * If the representation of the resource already exists,
187+ * return it, otherwise create a local representation and
188+ * return it.
189+ *
190+ * @param url - the remote URL of the resource to be retrieved.
191+ * @param install - specify if the resource should be installed (true) or not (false).
192+ * @param method - the method that will be used to install the resource
193+ * in case it is not installed and install install param is set true.
194+ *
195+ * @return a file pointing to a local materialization of the resource.
196+ * @throws Exception if the resource can not be located or some error occurs during
197+ * the local resource materialization.
198+ */
199+ public static File getResource (URL url , Install method , boolean install ) throws Exception {
200+ File resource = new File (URLToAbsolutePath (url ));
201+ if (!resource .exists () && !install ) {
202+ return null ;
203+ } else if (resource .exists () && !install ) {
204+ return resource ;
205+ }
206+ install (url , url , method );
207+ return resource ;
208+ }
209+
184210 /**
185211 * Get a local representation of the remote resource.
186212 * If the representation of the resource already exists,
@@ -266,4 +292,44 @@ public static void install(URL url, InputStream inputStream) throws Exception {
266292 fos .getChannel ().transferFrom (rbc , 0 , Long .MAX_VALUE );
267293 }
268294 }
295+
296+ /**
297+ * Publish a given file in a given URL local directory.
298+ * This function allows KBox to serve files to applications, acting as proxy to the publised file.
299+ * The file that is published in a give URL u will be located when the client execute
300+ * the function KBox.getResource(u).
301+ *
302+ * @param source - the URL of the file that is going to be published at the given URL.
303+ * @param dest - the URL where the file is going to be published. *
304+ * @param install - a customized method for installation.
305+ *
306+ * @throws Exception if the resource does not exist or can not be copied or some error
307+ * occurs during the resource publication.
308+ */
309+ public static void install (URL source , URL dest , Install install ) throws Exception {
310+ install .install (source , dest );
311+ }
312+
313+ /**
314+ * Install a given ZIP file from a given URL.
315+ *
316+ * @param source the source URL containing the ZIP file to be installed.
317+ * @param dest the URL whereas the source will be installed.
318+ * @throws Exception if an error occurs during the installation.
319+ */
320+ public static void installFromZip (URL source , URL dest ) throws Exception {
321+ ZipInstall zipInstall = new ZipInstall ();
322+ install (source , dest , zipInstall );
323+ }
324+
325+ /**
326+ * Install a given ZIP file from a given URL.
327+ *
328+ * @param source the source URL containing the ZIP file to be installed.
329+ * @throws Exception if an error occurs during the installation.
330+ */
331+ public static void installFromZip (URL source ) throws Exception {
332+ ZipInstall zipInstall = new ZipInstall ();
333+ install (source , source , zipInstall );
334+ }
269335}
0 commit comments