/** * Constructor for TarInputStream. * @param is the input stream to use * @param blockSize the block size to use * @param recordSize the record size to use */ public TarInputStream(InputStream is, int blockSize, int recordSize) { super(is); this.buffer = new TarBuffer(is, blockSize, recordSize); this.readBuf = null; this.oneBuf = new byte[1]; this.debug = false; this.hasHitEOF = false; }
/** * Closes this stream. Calls the TarBuffer's close() method. * @throws IOException on error */ public void close() throws IOException { this.buffer.close(); }
/** * Get the record size being used by this stream's TarBuffer. * * @return The TarBuffer record size. */ public int getRecordSize() { return this.buffer.getRecordSize(); }
/** * Get the next record in this tar archive. This will skip * over any remaining data in the current entry, if there * is one, and place the input stream at the header of the * next entry. * If there are no more entries in the archive, null will * be returned to indicate that the end of the archive has * been reached. * * @return The next header in the archive, or null. * @throws IOException on error */ private byte[] getRecord() throws IOException { if (hasHitEOF) { return null; } byte[] headerBuf = buffer.readRecord(); if (headerBuf == null) { if (debug) { System.err.println("READ NULL RECORD"); } hasHitEOF = true; } else if (buffer.isEOFRecord(headerBuf)) { if (debug) { System.err.println("READ EOF RECORD"); } hasHitEOF = true; } return hasHitEOF ? null : headerBuf; }
/** * Write an EOF (end of archive) record to the tar archive. * An EOF record consists of a record of all zeros. */ private void writeEOFRecord() throws IOException { for (int i = 0; i < this.recordBuf.length; ++i) { this.recordBuf[i] = 0; } this.buffer.writeRecord(this.recordBuf); } }
/** * Sets the debugging flag. * * @param debug True to turn on debugging. */ public void setDebug(boolean debug) { this.debug = debug; this.buffer.setDebug(debug); }
byte[] rec = this.buffer.readRecord();
/** * Write an EOF (end of archive) record to the tar archive. * An EOF record consists of a record of all zeros. */ private void writeEOFRecord() throws IOException { for (int i = 0; i < recordBuf.length; ++i) { recordBuf[i] = 0; } buffer.writeRecord(recordBuf); }
byte[] headerBuf = this.buffer.readRecord(); } else if (this.buffer.isEOFRecord(headerBuf)) { if (this.debug) { System.err.println("READ EOF RECORD");
/** * Sets the debugging flag in this stream's TarBuffer. * * @param debug True to turn on debugging. */ public void setBufferDebug(boolean debug) { this.buffer.setDebug(debug); }
byte[] rec = buffer.readRecord();
/** * Close an entry. This method MUST be called for all file * entries that contain data. The reason is that we must * buffer data written to the stream in order to satisfy * the buffer's record based writes. Thus, there may be * data fragments still being assembled that must be written * to the output stream before this entry is closed and the * next entry written. * @throws IOException on error */ public void closeEntry() throws IOException { if (this.assemLen > 0) { for (int i = this.assemLen; i < this.assemBuf.length; ++i) { this.assemBuf[i] = 0; } this.buffer.writeRecord(this.assemBuf); this.currBytes += this.assemLen; this.assemLen = 0; } if (this.currBytes < this.currSize) { throw new IOException("entry '" + currName + "' closed at '" + this.currBytes + "' before the '" + this.currSize + "' bytes specified in the header were written"); } }
byte[] headerBuf = this.buffer.readRecord(); } else if (this.buffer.isEOFRecord(headerBuf)) { if (this.debug) { System.err.println("READ EOF RECORD");
/** * Get the record size being used by this stream's TarBuffer. * * @return The TarBuffer record size. */ public int getRecordSize() { return this.buffer.getRecordSize(); }
/** * Closes this stream. Calls the TarBuffer's close() method. * @throws IOException on error */ @Override public void close() throws IOException { buffer.close(); }
/** * Sets the debugging flag. * * @param debug True to turn on debugging. */ public void setDebug(boolean debug) { this.debug = debug; buffer.setDebug(debug); }
/** * Constructor for TarInputStream. * @param os the output stream to use * @param blockSize the block size to use * @param recordSize the record size to use */ public TarOutputStream(OutputStream os, int blockSize, int recordSize) { super(os); this.buffer = new TarBuffer(os, blockSize, recordSize); this.debug = false; this.assemLen = 0; this.assemBuf = new byte[recordSize]; this.recordBuf = new byte[recordSize]; this.oneBuf = new byte[1]; }
byte[] rec = this.buffer.readRecord();
System.arraycopy(wBuf, wOffset, this.recordBuf, this.assemLen, aLen); this.buffer.writeRecord(this.recordBuf); this.buffer.writeRecord(wBuf, wOffset);
byte[] headerBuf = this.buffer.readRecord(); } else if (this.buffer.isEOFRecord(headerBuf)) { if (this.debug) { System.err.println("READ EOF RECORD");