/*
* Copyright 2013 Objectos, Fábrica de Software LTDA.
*
* Licensed 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 br.com.objectos.rio;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import br.com.objectos.way.cli.Cli;
import com.google.common.base.Throwables;
import com.google.common.io.ByteStreams;
import com.google.common.io.Resources;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
public class Rio {
public static void main(String[] args) {
RioModule module = new RioModule(Stage.PRODUCTION);
Injector injector = Guice.createInjector(module);
Cli cli = injector.getInstance(Cli.class);
cli.execute(args);
}
public static void copy(URL url, File file) {
RioRaw.INSTANCE.info("%s => %s", url, file.getAbsolutePath());
InputStream from = null;
OutputStream to = null;
try {
from = url.openStream();
to = new FileOutputStream(file);
ByteStreams.copy(from, to);
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
close(from);
close(to);
}
}
public static void close(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException e) {
}
}
}
public static File resourceAt(String resource) {
try {
URL url = Resources.getResource(Rio.class, resource);
return new File(url.toURI());
} catch (URISyntaxException e) {
throw Throwables.propagate(e);
}
}
}