yangys
2025-07-04 fc588c6e5ccac038cab378931d9bac3033e28f98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
            }
 
        }
    }
}