summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/TarArchiveUtil.java
blob: 09c4a2c5a533d5a28dca29fc2664353867c37234 (plain) (blame)
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.openslx.util;

import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarHeader;
import org.kamranzafar.jtar.TarOutputStream;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class TarArchiveUtil {



	public static void tarPutFile(TarOutputStream output, String fileName, String data) throws IOException
	{
		if (data == null)
			return;
		tarPutFile(output, fileName, data.getBytes(StandardCharsets.UTF_8));
	}

	public static void tarPutFile(TarOutputStream output, String fileName, byte[] data) throws IOException
	{
		if (data == null)
			return;
		output.putNextEntry(new TarEntry(
				TarHeader.createHeader(fileName, data.length, Util.unixTime(), false, 0644)));
		output.write(data);
	}
}