use of org.sonatype.nexus.repository.view.payloads.BytesPayload in project nexus-repository-r by sonatype-nexus-community.
the class RPackagesUtils method buildPackages.
public static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
for (Map<String, String> entry : entries) {
InternetHeaders headers = new InternetHeaders();
headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
headers.addHeader(P_VERSION, entry.get(P_VERSION));
headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
headers.addHeader(P_LINKINGTO, entry.get(P_LINKINGTO));
headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
Enumeration<String> headerLines = headers.getAllHeaderLines();
while (headerLines.hasMoreElements()) {
String line = headerLines.nextElement();
writer.write(line, 0, line.length());
writer.write('\n');
}
writer.write('\n');
}
}
} catch (CompressorException e) {
throw new RException(null, e);
}
return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}
use of org.sonatype.nexus.repository.view.payloads.BytesPayload in project nexus-repository-r by sonatype-nexus-community.
the class RHostedFacetImpl method getPackages.
@Override
@TransactionalTouchMetadata
public Content getPackages(final String packagesPath) {
checkNotNull(packagesPath);
try {
// TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
// the number of packages contained in a particular path. We should be able to generate this when something has
// changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
StorageTx tx = UnitOfWork.currentTx();
RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
packagesBuilder.append(asset);
}
CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation().entrySet()) {
Map<String, String> packageInfo = eachPackage.getValue();
InternetHeaders headers = new InternetHeaders();
headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION));
Enumeration<String> headerLines = headers.getAllHeaderLines();
while (headerLines.hasMoreElements()) {
String line = headerLines.nextElement();
writer.write(line, 0, line.length());
writer.write('\n');
}
writer.write('\n');
}
}
}
return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
} catch (CompressorException | IOException e) {
throw new RException(packagesPath, e);
}
}
use of org.sonatype.nexus.repository.view.payloads.BytesPayload in project nexus-repository-r by sonatype-nexus-community.
the class RPackagesUtils method buildPackages.
static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
for (Map<String, String> entry : entries) {
InternetHeaders headers = new InternetHeaders();
headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
headers.addHeader(P_VERSION, entry.get(P_VERSION));
headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
Enumeration<String> headerLines = headers.getAllHeaderLines();
while (headerLines.hasMoreElements()) {
String line = headerLines.nextElement();
writer.write(line, 0, line.length());
writer.write('\n');
}
writer.write('\n');
}
}
} catch (CompressorException e) {
throw new RException(null, e);
}
return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}
Aggregations