import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
// super-short version
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
class main {
static String uploadData(String pathToDataFile) {
File file = new File(pathToDataFile);
return uploadData(programID(), file.getAbsolutePath(), file);
}
static String uploadData(File file) {
return uploadData(programID(), file.getAbsolutePath(), file);
}
static String uploadData(String gummipw, String title, File dataFile) { try {
return uploadData(gummipw, title, loadBinaryFile(dataFile), false);
} catch (Exception __e) { throw rethrow(__e); } }
static String uploadDataSuperHigh(String gummipw, String title, File dataFile) { try {
return uploadData(gummipw, title, loadBinaryFile(dataFile), true);
} catch (Exception __e) { throw rethrow(__e); } }
static String uploadData(String gummipw, String title, byte[] data) throws IOException {
return uploadData(gummipw, title, data, false);
}
static String uploadData(String gummipw, String title, byte[] data, boolean superhigh) throws IOException {
if (gummipw == null || gummipw.length() == 0)
throw new RuntimeException("Need gummi password.");
System.out.println("Uploading:");
System.out.println(" gummipw: " + gummipw);
System.out.println(" " + title);
int displayLength = 40;
System.out.println(" " + data.length + " bytes of data");
URL url = new URL("http://tinybrain.de:8080/tb-int/add_snippet.php");
String postData =
"gummipw=" + URLEncoder.encode(unnull(gummipw), "UTF-8")
+ "&blob=" + URLEncoder.encode(base64encode(data), "UTF-8")
+ "&name=" + URLEncoder.encode(unnull(title), "UTF-8")
+ "&type=" + 37 /* SN_DATA */
+ "&" + (superhigh ? "superhigh" : "high") + "=1&public=1";
System.out.println("Post data length: " + postData.length());
String contents = doPost(postData, url.openConnection(), url);
System.out.println(contents);
if (isInteger(contents)) {
long id = parseSnippetID(contents);
System.out.println("=> #" + id);
return "#" + id;
} else
throw new RuntimeException("Server error: " + contents);
}
static String programID() {
return getProgramID();
}
static String programID(Object o) {
return getProgramID(o);
}
public static byte[] loadBinaryFile(String fileName) {
try {
if (!new File(fileName).exists())
return null;
FileInputStream in = new FileInputStream(fileName);
byte buf[] = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
int l;
while (true) {
l = in.read(buf);
if (l <= 0) break;
out.write(buf, 0, l);
}
in.close();
return out.toByteArray();
} catch (IOException e) { throw new RuntimeException(e); }
}
public static byte[] loadBinaryFile(File file) {
return loadBinaryFile(file.getPath());
}
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static String unnull(String s) {
return s == null ? "" : s;
}
static Collection unnull(Collection l) {
return l == null ? emptyList() : l;
}
static List unnull(List l) {
return l == null ? emptyList() : l;
}
static Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
static Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
static A[] unnull(A[] a) {
return a == null ? (A[]) new Object[0] : a;
}
static BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
//ifclass Symbol
static Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
static String base64encode(byte[] a) {
int aLen = a.length;
int numFullGroups = aLen/3;
int numBytesInPartialGroup = aLen - 3*numFullGroups;
int resultLen = 4*((aLen + 2)/3);
StringBuffer result = new StringBuffer(resultLen);
char[] intToAlpha = intToBase64;
// Translate all full groups from byte array elements to Base64
int inCursor = 0;
for (int i=0; i> 2]);
result.append(intToAlpha[(byte0 << 4)&0x3f | (byte1 >> 4)]);
result.append(intToAlpha[(byte1 << 2)&0x3f | (byte2 >> 6)]);
result.append(intToAlpha[byte2 & 0x3f]);
}
// Translate partial group if present
if (numBytesInPartialGroup != 0) {
int byte0 = a[inCursor++] & 0xff;
result.append(intToAlpha[byte0 >> 2]);
if (numBytesInPartialGroup == 1) {
result.append(intToAlpha[(byte0 << 4) & 0x3f]);
result.append("==");
} else {
// assert numBytesInPartialGroup == 2;
int byte1 = a[inCursor++] & 0xff;
result.append(intToAlpha[(byte0 << 4)&0x3f | (byte1 >> 4)]);
result.append(intToAlpha[(byte1 << 2)&0x3f]);
result.append('=');
}
}
// assert inCursor == a.length;
// assert result.length() == resultLen;
return result.toString();
}
/**
* This array is a lookup table that translates 6-bit positive integer
* index values into their "Base64 Alphabet" equivalents as specified
* in Table 1 of RFC 2045.
*/
static final char intToBase64[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
static ThreadLocal doPost_silently = new ThreadLocal();
static ThreadLocal doPost_timeout = new ThreadLocal();
static ThreadLocal