Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
do not read datastream contents into a string before exporting in arc…
Browse files Browse the repository at this point in the history
…hive format for FOXML
  • Loading branch information
barmintor committed Mar 21, 2015
1 parent d99c1db commit a1aa0db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
public interface DOSerializer {

static final char [] DS_INDENT = " ".toCharArray();

/**
* Get a new serializer with the same format as this one, safe
* for use in the current thread. Thread-safe implementations may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
package org.fcrepo.server.storage.translation;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
Expand All @@ -26,7 +28,6 @@
import org.fcrepo.server.storage.types.DigitalObject;
import org.fcrepo.server.storage.types.Disseminator;
import org.fcrepo.server.utilities.StreamUtility;
import org.fcrepo.server.utilities.StringUtility;
import org.fcrepo.utilities.Base64;
import org.fcrepo.utilities.DateUtility;
import org.slf4j.Logger;
Expand Down Expand Up @@ -367,15 +368,7 @@ private void appendDatastreams(DigitalObject obj,
// if M insert ds content location as an internal identifier
} else if (vds.DSControlGrp.equalsIgnoreCase("M")) {
if (transContext == DOTranslationUtility.SERIALIZE_EXPORT_ARCHIVE) {
writer.print('<');
writer.print(FOXML.prefix);
writer.print(":binaryContent> \n");
String encoded = Base64.encodeToString(vds.getContentStream());
StringUtility.splitAndIndent(encoded,
14, 80, writer);
writer.print("</");
writer.print(FOXML.prefix);
writer.print(":binaryContent> \n");
serializeDatastreamContent(vds, writer);
} else {
writer.print('<');
writer.print(FOXML.prefix);
Expand Down Expand Up @@ -406,6 +399,29 @@ private void appendDatastreams(DigitalObject obj,
}
}

protected void serializeDatastreamContent(Datastream dsc, PrintWriter writer)
throws StreamIOException {
writer.print("<");
writer.print(FOXML.prefix);
writer.print(":binaryContent> \n");
Reader encoded = new InputStreamReader(Base64.encodeToStream(dsc.getContentStream()));
char [] buffer = new char[80];
int len = 0;

try{
while ((len = encoded.read(buffer)) > -1){
writer.write(DOSerializer.DS_INDENT);
writer.write(buffer,0,len);
writer.write('\n');
}
} catch (IOException ioe) {
throw new StreamIOException(ioe.getMessage());
}
writer.print("</");
writer.print(FOXML.prefix);
writer.print(":binaryContent> \n");
}

private void appendAudit(DigitalObject obj,
PrintWriter writer,
String encoding, int transContext) throws ObjectIntegrityException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class METSFedoraExtDOSerializer
private static final Logger logger =
LoggerFactory.getLogger(METSFedoraExtDOSerializer.class);

private static final char [] DS_INDENT = " ".toCharArray();

/** The format this serializer writes. */
private final XMLFormat m_format;

Expand Down Expand Up @@ -630,7 +628,7 @@ protected void serializeDatastreamContent(Datastream dsc, PrintWriter writer)

try{
while ((len = encoded.read(buffer)) > -1){
writer.write(DS_INDENT);
writer.write(DOSerializer.DS_INDENT);
writer.write(buffer,0,len);
writer.write('\n');
}
Expand Down

0 comments on commit a1aa0db

Please sign in to comment.