use of com.google.common.io.ByteSource in project GeoGig by boundlessgeo.
the class Logging method getOrCreateLoggingConfigFile.
@Nullable
private static URL getOrCreateLoggingConfigFile(final File geogigdir) {
final File logsDir = new File(geogigdir, "log");
if (!logsDir.exists() && !logsDir.mkdir()) {
return null;
}
final File configFile = new File(logsDir, "logback.xml");
if (configFile.exists()) {
try {
return configFile.toURI().toURL();
} catch (MalformedURLException e) {
throw Throwables.propagate(e);
}
}
ByteSource from;
final URL resource = GeogigCLI.class.getResource("logback_default.xml");
try {
from = Resources.asByteSource(resource);
} catch (NullPointerException npe) {
LOGGER.warn("Couldn't obtain default logging configuration file");
return null;
}
try {
from.copyTo(Files.asByteSink(configFile));
return configFile.toURI().toURL();
} catch (Exception e) {
LOGGER.warn("Error copying logback_default.xml to {}. Using default configuration.", configFile, e);
return resource;
}
}
use of com.google.common.io.ByteSource in project mica2 by obiba.
the class StudyPackageImportServiceImpl method importNetwork.
private void importNetwork(Network network, boolean publish, StudyPackage studyPackage) throws IOException {
Network updated;
try {
Network existing = networkService.findById(network.getId());
network.getStudyIds().stream().filter(sid -> !existing.getStudyIds().contains(sid)).forEach(sid -> existing.getStudyIds().add(sid));
updated = existing;
} catch (NoSuchNetworkException e) {
updated = network;
}
for (Map.Entry<String, ByteSource> e : studyPackage.attachments.entrySet()) {
Attachment attachment = network.getLogo();
if (attachment != null && attachment.getId().equals(e.getKey())) {
saveTempFile(attachment, e.getValue());
updated.setLogo(attachment);
}
}
networkService.save(updated);
if (publish)
networkService.publish(updated.getId(), true, PublishCascadingScope.ALL);
}
use of com.google.common.io.ByteSource in project wombat by PLOS.
the class PowerPointController method getImageFile.
private ByteSource getImageFile(AssetPointer assetId) throws IOException {
Map<String, ?> files = articleService.getItemFiles(assetId);
Map<String, ?> file = (Map<String, ?>) files.get(IMAGE_SIZE);
ContentKey key = ContentKey.createForUuid((String) file.get("crepoKey"), UUID.fromString((String) file.get("crepoUuid")));
return new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return corpusContentApi.request(key, ImmutableList.of()).getEntity().getContent();
}
};
}
use of com.google.common.io.ByteSource in project grafikon by jub77.
the class FileLoadSaveImages method saveTimetableImage.
/**
* saves image for timetable.
*
* @param image image
* @param os zip output stream
* @throws java.io.IOException
*/
public void saveTimetableImage(TimetableImage image, ZipOutputStream os) throws IOException {
// copy image to zip
ZipEntry entry = new ZipEntry(location + image.getFilename());
if (image.getImageFile() == null) {
// skip images without image file
log.warn("Skipping image {} because the gtm doesn't contain a file.", image.getFilename());
return;
}
ByteSource src = Files.asByteSource(image.getImageFile());
entry.setSize(src.size());
os.putNextEntry(entry);
src.copyTo(os);
}
use of com.google.common.io.ByteSource in project grafikon by jub77.
the class ResourceHelper method readResource.
public static String readResource(final String filename, final ClassLoader cl) {
try {
ByteSource bs = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return getStream(filename, cl);
}
};
CharSource cs = bs.asCharSource(StandardCharsets.UTF_8);
return cs.read();
} catch (IOException e) {
log.warn(e.getMessage(), e);
return "";
}
}
Aggregations