package org.springblade.mdm.utils; import java.io.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class CustomBinaryWriter { static final byte[] MAGIC_NUMBER = {'M', 'D', 'M', '1'}; static final short VERSION = 1; /** * 将输入流中的内容写入输出流 * @param outputStream * @param ins * @throws IOException */ public static void write(OutputStream outputStream, InputStream ins) throws IOException { byte[] buffer = new byte[1024]; try (DataOutputStream out = new DataOutputStream(outputStream)) { // 写入文件头 out.write(MAGIC_NUMBER); out.writeShort(VERSION); while(ins.read(buffer) != -1) { out.write(buffer); } } } }