private void processProperty(String name, Property property)
throws RepositoryException {
InputStream contentStream = null;
InputStream encodedContentStream = null;
try {
Value v = property.nextValue();
// if we have a contentfile property, we want to stream the InputStream
// to demonstrate that we don't blow up memory
if (v instanceof BinaryValue) {
contentStream = ((BinaryValue) v).getInputStream();
if (null != contentStream) {
encodedContentStream = new Base64FilterInputStream(contentStream);
}
int totalBytesRead = 0;
if (null != encodedContentStream) {
int bytesRead = 0;
byte[] b = new byte[16384];
try {
while (-1 != (bytesRead = encodedContentStream.read(b))) {
totalBytesRead += bytesRead;
}
} catch (IOException e) {
throw new RepositoryDocumentException(
"Error reading content stream.", e);
}
}
printStream.println("Total bytes read in base64 encoded file: "
+ totalBytesRead);
}
do {
printStream.println("<" + name + ">");
printStream.println(v.toString());
printStream.println("</" + name + ">");
} while ((v = property.nextValue()) != null);
} finally {
if (null != encodedContentStream) {
try { encodedContentStream.close(); } catch (IOException e) {}