-
Notifications
You must be signed in to change notification settings - Fork 79
/
LocalTextFile.java
58 lines (46 loc) · 1.26 KB
/
LocalTextFile.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package mod.chiselsandbits.share.output;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import mod.chiselsandbits.blueprints.BlueprintData;
import mod.chiselsandbits.helpers.LocalStrings;
public class LocalTextFile implements IShareOutput
{
File outFile;
final String encoding = "UTF-8";
public LocalTextFile(
final File file )
{
outFile = file;
}
@Override
public String handleOutput(
final byte[] compressedData,
final BufferedImage screenshot ) throws UnsupportedEncodingException, IOException
{
final FileOutputStream o = new FileOutputStream( outFile );
o.write( new String( "[C&B](" ).getBytes( encoding ) );
o.write( Base64.getEncoder().encodeToString( compressedData ).getBytes( encoding ) );
o.write( new String( ")[C&B]" ).getBytes( encoding ) );
o.close();
return LocalStrings.ShareFile.toString();
}
@Override
public BlueprintData getData()
{
BlueprintData bpd = new BlueprintData( null );
try
{
bpd.setLocalSource( outFile.getAbsolutePath() );
bpd.loadData( new FileInputStream( outFile ) );
}
catch ( IOException e )
{
}
return bpd;
}
}