|
|
@ -8,8 +8,11 @@ import java.io.FileWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.Reader; |
|
|
|
import java.io.Reader; |
|
|
|
|
|
|
|
import java.io.Writer; |
|
|
|
import java.net.ConnectException; |
|
|
|
import java.net.ConnectException; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
@ -18,6 +21,7 @@ import java.nio.channels.Channels; |
|
|
|
import java.nio.channels.FileChannel; |
|
|
|
import java.nio.channels.FileChannel; |
|
|
|
import java.nio.channels.ReadableByteChannel; |
|
|
|
import java.nio.channels.ReadableByteChannel; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -258,6 +262,7 @@ public class FileUtils { |
|
|
|
logToFile(message,filename,false); |
|
|
|
logToFile(message,filename,false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void logToFile(String message, String filename, boolean outputToChatLog) { |
|
|
|
public static void logToFile(String message, String filename, boolean outputToChatLog) { |
|
|
|
File file = new File(filename); |
|
|
|
File file = new File(filename); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -265,9 +270,9 @@ public class FileUtils { |
|
|
|
if (!file.exists()) { |
|
|
|
if (!file.exists()) { |
|
|
|
file.createNewFile(); |
|
|
|
file.createNewFile(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
OutputStream out = new FileOutputStream(file,true); |
|
|
|
FileWriter fw = new FileWriter(file, true); |
|
|
|
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); |
|
|
|
PrintWriter pw = new PrintWriter(fw); |
|
|
|
PrintWriter pw = new PrintWriter(writer); |
|
|
|
|
|
|
|
|
|
|
|
pw.println(message); |
|
|
|
pw.println(message); |
|
|
|
pw.flush(); |
|
|
|
pw.flush(); |
|
|
@ -353,7 +358,7 @@ public class FileUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void downloadFileFromUrl(String url, String file,boolean bearer) throws IOException, JSONException { |
|
|
|
public static void downloadFileFromUrl(String url, String file) throws IOException, JSONException { |
|
|
|
File filer = new File(file); |
|
|
|
File filer = new File(file); |
|
|
|
filer.createNewFile(); |
|
|
|
filer.createNewFile(); |
|
|
|
|
|
|
|
|
|
|
@ -364,12 +369,6 @@ public class FileUtils { |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
connection.setRequestMethod("GET"); |
|
|
|
connection.setRequestMethod("GET"); |
|
|
|
//connection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
//connection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
connection.setRequestProperty("Accept", "application/vnd.twitchtv.v5+json"); |
|
|
|
|
|
|
|
connection.setRequestProperty("Authorization", ((bearer)?"Bearer":"OAuth") + " "+sigIRC.oauth.replace("oauth:", "")); |
|
|
|
|
|
|
|
if (sigIRC.CLIENTID.length()!=0) { |
|
|
|
|
|
|
|
connection.setRequestProperty("Client-ID", sigIRC.CLIENTID); |
|
|
|
|
|
|
|
//System.out.println("Using "+ sigIRC.oauth+"/"+sigIRC.CLIENTID);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream()); |
|
|
|
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream()); |
|
|
|
FileOutputStream fos = new FileOutputStream(file); |
|
|
|
FileOutputStream fos = new FileOutputStream(file); |
|
|
@ -379,8 +378,4 @@ public class FileUtils { |
|
|
|
System.out.println("Failed to connect, moving on..."); |
|
|
|
System.out.println("Failed to connect, moving on..."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void downloadFileFromUrl(String url, String file) throws IOException, JSONException { |
|
|
|
|
|
|
|
downloadFileFromUrl(url,file,false); //Uses OAUTH instead of Bearer
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|