private void writeHeader(CpioArchiveEntry e) //throws IOException { switch (e.getFormat()) { case CpioConstants.FORMAT_NEW: outJ.write(ArchiveUtils.toAsciiBytes(CpioConstants.MAGIC_NEW)); count(6); writeNewEntry(e); break; case CpioConstants.FORMAT_NEW_CRC: outJ.write(ArchiveUtils.toAsciiBytes(CpioConstants.MAGIC_NEW_CRC)); count(6); writeNewEntry(e); break; case CpioConstants.FORMAT_OLD_ASCII: outJ.write(ArchiveUtils.toAsciiBytes(CpioConstants.MAGIC_OLD_ASCII)); count(6); writeOldAsciiEntry(e); break; case CpioConstants.FORMAT_OLD_BINARY: bool swapHalfWord = true; writeBinaryLong(CpioConstants.MAGIC_OLD_BINARY, 2, swapHalfWord); writeOldBinaryEntry(e, swapHalfWord); break; } }
/** * Begins writing a new CPIO file entry and positions the stream to the * start of the entry data. Closes the current entry if still active. The * current time will be used if the entry has no set modification time and * the default header format will be used if no other format is specified in * the entry. * * @param entry * the CPIO cpioEntry to be written * @throws IOException * if an I/O error has occurred or if a CPIO file error has * occurred * @throws ClassCastException if entry is not an instance of CpioArchiveEntry */ public override void putArchiveEntry(ArchiveEntry entry) //throws IOException { if (finished) { throw new java.io.IOException("Stream has already been finished"); } CpioArchiveEntry e = (CpioArchiveEntry)entry; ensureOpen(); if (this.entry != null) { closeArchiveEntry(); // close previous entry } if (e.getTime() == -1) { e.setTime(java.lang.SystemJ.currentTimeMillis() / 1000); } short format = e.getFormat(); if (format != this.entryFormat) { throw new java.io.IOException("Header format: " + format + " does not match existing format: " + this.entryFormat); } if (this.names.put(e.getName(), e) != null) { throw new java.io.IOException("duplicate entry: " + e.getName()); } writeHeader(e); this.entry = e; this.written = 0; }