+ /**
+ * write data from a stream into an appData reference.
+ * @param AppDataReference - New AppDataReference not already written to archive
+ * @param adstream Source of data for appData reference - read until .read(buffer) returns -1
+ * @return true on success.
+ * @throws IOException for file IO or invalid AppDataReference string
+ */
+ public boolean writeAppdataFromStream(String AppDataReference, java.io.InputStream adstream) throws IOException {
+ if (!_validNewAppDataReference(AppDataReference)) {
+ log.warn("Invalid AppDataReference passed to writeAppdataFromStream");
+ throw new IOException("Invalid AppDataReference! (null, or maybe non-unique)!");
+ }
+
+ if (AppDataReference==null) {
+ log.warn("null appdata passed.");
+ throw new IOException("Null AppDataReference");
+ }
+
+ java.io.OutputStream adout = getAppDataStream(AppDataReference);
+ // copy over the bytes
+ int written=-1;
+ long count=0;
+ byte[] buffer = new byte[_TRANSFER_BUFFER]; // conservative estimate of a sensible buffer
+ do {
+ if ((written = adstream.read(buffer))>-1) {
+ adout.write(buffer, 0, written);
+ log.debug("Transferring "+written+".");
+ count+=written;
+ }
+ } while (written>-1);
+ return true;
+ }