/PatreonHelper.java Secret
Created
July 14, 2016 16:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fireball1725.graves.common.helpers; | |
import com.fireball1725.graves.Graves; | |
import com.fireball1725.graves.common.reference.ModInfo; | |
import com.google.common.collect.Maps; | |
import com.google.common.reflect.TypeToken; | |
import com.google.gson.Gson; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.util.Map; | |
public class PatreonHelper | |
{ | |
public static Map<String, Map<String, String>> getSpecialText() | |
{ | |
Map<String, Map<String, String>> specialText = Maps.newHashMap(); | |
try | |
{ | |
specialText = new Gson().fromJson(readUrl("http://pastebin.com/raw/" + ModInfo.SPECIAL_TEXT), new TypeToken<Map<String, Map<String, String>>>(){}.getType()); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
return specialText; | |
} | |
private static String readUrl(String urlString) throws Exception { | |
BufferedReader reader = null; | |
try { | |
URL url = new URL(urlString); | |
reader = new BufferedReader(new InputStreamReader(url.openStream())); | |
StringBuffer buffer = new StringBuffer(); | |
int read; | |
char[] chars = new char[1024]; | |
while ((read = reader.read(chars)) != -1) | |
buffer.append(chars, 0, read); | |
return buffer.toString(); | |
} finally { | |
if (reader != null) | |
reader.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment