public static void outputItem(String itemName, String contentType, int fileType, long length,
			InputStream content, File packedFile, TaskMonitor monitor) throws CancelledException,
			IOException {

		OutputStream out = new BufferedOutputStream(new FileOutputStream(packedFile));
		boolean success = false;
		try {
			// Output header containing: original item name and content type
			ObjectOutputStream objOut = new ObjectOutputStream(out);
			objOut.writeLong(MAGIC_NUMBER);
			objOut.writeInt(FORMAT_VERSION);
			objOut.writeUTF(itemName);
			objOut.writeUTF(contentType != null ? contentType : "");
			objOut.writeInt(fileType);
			objOut.writeLong(length);
			objOut.flush();

			// Output item content
			ZipOutputStream zipOut = new ZipOutputStream(out);
			ZipEntry entry = new ZipEntry(ZIP_ENTRY_NAME);
			entry.setSize(length);
			entry.setMethod(ZipEntry.DEFLATED);
			zipOut.putNextEntry(entry);

			OutputStream itemOut = zipOut;
			if (monitor != null) {
				itemOut = new MonitoredOutputStream(zipOut, monitor);
				monitor.initialize((int) length);
			}

			long lengthWritten = 0;
			byte[] buffer = new byte[IO_BUFFER_SIZE];

			// Copy file contents
			int cnt = 0;
			while ((cnt = content.read(buffer)) > 0) {
				itemOut.write(buffer, 0, cnt);
				lengthWritten += cnt;
			}

			if (lengthWritten != length) {
				throw new IOException("Did not write all content - written length is " +
					lengthWritten + ", expected " + length + ".\n\tItem: " + itemName + " in " +
					"packed file: " + packedFile.getAbsolutePath());
			}
			itemOut.flush();

			zipOut.closeEntry();
			zipOut.flush();
			success = true;
		}
		catch (IOCancelledException e) {
			throw new CancelledException();
		}
		finally {
			try {
				out.close();
				if (!success) {
					packedFile.delete();
				}
			}
			catch (IOException e) {
				// we tried
			}
		}
	}
Read and compress data from the specified content stream and write to 
a packed file along with additional meta-data.
@param itemName item name
@param contentType content type
@param fileType file type
@param length content length to be read
@param content content input stream
@param packedFile output packed file to be created
@param monitor task monitor
@throws CancelledException if output is cancelled
@throws IOException if IO error occurs
Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/ItemSerializer.java