
br.com.objectos.rio.HttpServer Maven / Gradle / Ivy
The newest version!
/*
* Server.java criado em 05/01/2014
*
* Propriedade de Objectos Fábrica de Software LTDA.
* Reprodução parcial ou total proibida.
*/
package br.com.objectos.rio;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import br.com.objectos.way.core.io.Directory;
import com.google.common.base.Throwables;
/**
* @author [email protected] (Marcio Endo)
*/
public class HttpServer {
private final String server;
private HttpServer(String server) {
this.server = server;
}
public static HttpServer at(String server) {
return new HttpServer(server);
}
public URL urlAt(String url) {
try {
String spec = String.format("http://%s/%s", server, url);
return new URL(spec);
} catch (MalformedURLException e) {
throw Throwables.propagate(e);
}
}
public HttpServerDownload download(String url) {
return new HttpServerDownload(url);
}
public class HttpServerDownload {
private final URL url;
private final String name;
public HttpServerDownload(String url) {
this.url = urlAt(url);
String name = url;
int index = url.lastIndexOf('/');
if (index > 0) {
name = url.substring(index);
}
this.name = name;
}
public void toDir(Directory target) {
File file = target.fileAt(name);
RioBootstrap.copy(url, file);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy