use of org.sonatype.nexus.repository.r.internal.RException 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.r.internal.RException in project nexus-repository-r by sonatype-nexus-community.
the class RMetadataUtils method parseDescriptionFile.
/**
* Parses metadata stored in a Debian Control File-like format.
*
* @see <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file">Description File</a>
*/
public static Map<String, String> parseDescriptionFile(final InputStream in) {
checkNotNull(in);
try {
LinkedHashMap<String, String> results = new LinkedHashMap<>();
InternetHeaders headers = new InternetHeaders(in);
Enumeration headerEnumeration = headers.getAllHeaders();
while (headerEnumeration.hasMoreElements()) {
Header header = (Header) headerEnumeration.nextElement();
String name = header.getName();
String value = header.getValue().replace("\r\n", "\n").replace("\r", // TODO: "should" be ASCII only, otherwise need to know encoding?
"\n");
// TODO: Supposedly no duplicates, is this true?
results.put(name, value);
}
return results;
} catch (MessagingException e) {
throw new RException(null, e);
}
}
use of org.sonatype.nexus.repository.r.internal.RException in project nexus-repository-r by sonatype-nexus-community.
the class RPackagesUtils method parseMetadata.
public static List<Map<String, String>> parseMetadata(final InputStream in) {
List<Map<String, String>> entries = new ArrayList<>();
try (InputStreamReader inr = new InputStreamReader(in, UTF_8)) {
try (BufferedReader br = new BufferedReader(inr)) {
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
if (line.trim().isEmpty()) {
String content = sb.toString();
if (!content.trim().isEmpty()) {
entries.add(parseDescriptionFile(new ByteArrayInputStream(content.getBytes(UTF_8))));
}
sb = new StringBuilder();
} else {
sb.append(line);
sb.append('\n');
}
}
String content = sb.toString();
if (!content.trim().isEmpty()) {
entries.add(parseDescriptionFile(new ByteArrayInputStream(content.getBytes(UTF_8))));
}
}
return entries;
} catch (IOException e) {
throw new RException(null, e);
}
}
Aggregations