private void writeHeader(final CpioArchiveEntry e) throws IOException {
   switch (e.getFormat()) {
     case FORMAT_NEW:
       out.write(ArchiveUtils.toAsciiBytes(MAGIC_NEW));
       count(6);
       writeNewEntry(e);
       break;
     case FORMAT_NEW_CRC:
       out.write(ArchiveUtils.toAsciiBytes(MAGIC_NEW_CRC));
       count(6);
       writeNewEntry(e);
       break;
     case FORMAT_OLD_ASCII:
       out.write(ArchiveUtils.toAsciiBytes(MAGIC_OLD_ASCII));
       count(6);
       writeOldAsciiEntry(e);
       break;
     case FORMAT_OLD_BINARY:
       final boolean swapHalfWord = true;
       writeBinaryLong(MAGIC_OLD_BINARY, 2, swapHalfWord);
       writeOldBinaryEntry(e, swapHalfWord);
       break;
     default:
       throw new IOException("unknown format " + e.getFormat());
   }
 }
  private void writeAsciiLong(final long number, final int length, final int radix)
      throws IOException {
    final StringBuilder tmp = new StringBuilder();
    String tmpStr;
    if (radix == 16) {
      tmp.append(Long.toHexString(number));
    } else if (radix == 8) {
      tmp.append(Long.toOctalString(number));
    } else {
      tmp.append(Long.toString(number));
    }

    if (tmp.length() <= length) {
      final int insertLength = length - tmp.length();
      for (int pos = 0; pos < insertLength; pos++) {
        tmp.insert(0, "0");
      }
      tmpStr = tmp.toString();
    } else {
      tmpStr = tmp.substring(tmp.length() - length);
    }
    final byte[] b = ArchiveUtils.toAsciiBytes(tmpStr);
    out.write(b);
    count(b.length);
  }