896 bytesForDump = null; // GC
897 }
898
899 // alternative to readFrom:
900 public void setInputStreamFrom(InputStream in) throws IOException {
901 assert(bytes == null);
902 assert(assertReadyToReadFrom(this, in));
903 setPhase(READ_PHASE);
904 this.in = in;
905 if (optDumpBands) {
906 // Tap the stream.
907 bytesForDump = new ByteArrayOutputStream();
908 this.in = new FilterInputStream(in) {
909 @Override
910 public int read() throws IOException {
911 int ch = in.read();
912 if (ch >= 0) bytesForDump.write(ch);
913 return ch;
914 }
915 @Override
916 public int read(byte b[], int off, int len) throws IOException {
917 int nr = in.read(b, off, len);
918 if (nr >= 0) bytesForDump.write(b, off, nr);
919 return nr;
920 }
921 };
922 }
923 super.readyToDisburse();
924 }
925
926 public OutputStream collectorStream() {
927 assert(phase() == COLLECT_PHASE);
928 assert(bytes != null);
929 return bytes;
930 }
931
932 public InputStream getInputStream() {
933 assert(phase() == DISBURSE_PHASE);
934 assert(in != null);
935 return in;
936 }
1361 */
1362 private static
1363 class ByteCounter extends FilterOutputStream {
1364 // (should go public under the name CountingOutputStream?)
1365
1366 private long count;
1367
1368 public ByteCounter(OutputStream out) {
1369 super(out);
1370 }
1371
1372 public long getCount() { return count; }
1373 public void setCount(long c) { count = c; }
1374
1375 @Override
1376 public void write(int b) throws IOException {
1377 count++;
1378 if (out != null) out.write(b);
1379 }
1380 @Override
1381 public void write(byte b[], int off, int len) throws IOException {
1382 count += len;
1383 if (out != null) out.write(b, off, len);
1384 }
1385 @Override
1386 public String toString() {
1387 return String.valueOf(getCount());
1388 }
1389 }
1390 ByteCounter outputCounter;
1391
1392 void writeAllBandsTo(OutputStream out) throws IOException {
1393 // Wrap a byte-counter around the output stream.
1394 outputCounter = new ByteCounter(out);
1395 out = outputCounter;
1396 all_bands.writeTo(out);
1397 if (verbose > 0) {
1398 long nbytes = outputCounter.getCount();
1399 Utils.log.info("Wrote total of "+nbytes+" bytes.");
1400 assert(nbytes == archiveSize0+archiveSize1);
1401 }
|
896 bytesForDump = null; // GC
897 }
898
899 // alternative to readFrom:
900 public void setInputStreamFrom(InputStream in) throws IOException {
901 assert(bytes == null);
902 assert(assertReadyToReadFrom(this, in));
903 setPhase(READ_PHASE);
904 this.in = in;
905 if (optDumpBands) {
906 // Tap the stream.
907 bytesForDump = new ByteArrayOutputStream();
908 this.in = new FilterInputStream(in) {
909 @Override
910 public int read() throws IOException {
911 int ch = in.read();
912 if (ch >= 0) bytesForDump.write(ch);
913 return ch;
914 }
915 @Override
916 public int read(byte[] b, int off, int len) throws IOException {
917 int nr = in.read(b, off, len);
918 if (nr >= 0) bytesForDump.write(b, off, nr);
919 return nr;
920 }
921 };
922 }
923 super.readyToDisburse();
924 }
925
926 public OutputStream collectorStream() {
927 assert(phase() == COLLECT_PHASE);
928 assert(bytes != null);
929 return bytes;
930 }
931
932 public InputStream getInputStream() {
933 assert(phase() == DISBURSE_PHASE);
934 assert(in != null);
935 return in;
936 }
1361 */
1362 private static
1363 class ByteCounter extends FilterOutputStream {
1364 // (should go public under the name CountingOutputStream?)
1365
1366 private long count;
1367
1368 public ByteCounter(OutputStream out) {
1369 super(out);
1370 }
1371
1372 public long getCount() { return count; }
1373 public void setCount(long c) { count = c; }
1374
1375 @Override
1376 public void write(int b) throws IOException {
1377 count++;
1378 if (out != null) out.write(b);
1379 }
1380 @Override
1381 public void write(byte[] b, int off, int len) throws IOException {
1382 count += len;
1383 if (out != null) out.write(b, off, len);
1384 }
1385 @Override
1386 public String toString() {
1387 return String.valueOf(getCount());
1388 }
1389 }
1390 ByteCounter outputCounter;
1391
1392 void writeAllBandsTo(OutputStream out) throws IOException {
1393 // Wrap a byte-counter around the output stream.
1394 outputCounter = new ByteCounter(out);
1395 out = outputCounter;
1396 all_bands.writeTo(out);
1397 if (verbose > 0) {
1398 long nbytes = outputCounter.getCount();
1399 Utils.log.info("Wrote total of "+nbytes+" bytes.");
1400 assert(nbytes == archiveSize0+archiveSize1);
1401 }
|