This file contains 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
URL[] paths = CollectionUtil.stream(Arrays.asList(cp.split(File.pathSeparator))) | |
.map(new Function<String, URL>() { | |
public URL apply(String value) { | |
try { | |
return new File(value).toURI().toURL(); | |
} catch (MalformedURLException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
}) |
This file contains 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
Arrays.stream(new File("lib").listFiles(f -> f.getName().endsWith(".jar"))) | |
.map(f -> f.getAbsolutePath()) | |
.reduce(".", (l, r) -> l + File.pathSeparator + r) |
This file contains 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
public class MsgPackTest { | |
public static void main(String[] args) throws Exception { | |
MessagePack msgpack = new MessagePack(); | |
List<String> lines = Arrays.asList("hello", "world"); | |
byte[] bytes = msgpack.write(lines); | |
msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance())); | |
for(Value v: (List<Value>)msgpack.read(bytes, List.class)){ | |
System.out.println(new String(v.asRawValue().getByteArray(), "UTF-8")); | |
} | |
} |
This file contains 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 seimei; | |
import jp.go.nict.langrid.commons.util.Pair; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Arrays; |
This file contains 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
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.ObjectStreamClass; | |
import java.net.URL; | |
import java.net.URLClassLoader; | |
import java.nio.file.Paths; | |
import java.util.HashMap; |
This file contains 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
import org.trie4j.doublearray.DoubleArray; | |
import org.trie4j.louds.LOUDSTrie; | |
import org.trie4j.patricia.simple.PatriciaTrie; | |
public class Sample { | |
public static void main(String[] args) throws Exception{ | |
PatriciaTrie pat = new PatriciaTrie(); | |
pat.insert("Hello"); | |
pat.insert("World"); | |
pat.insert("Wonder"); |
This file contains 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
// workaround for http://jira.twitter4j.org/browse/TFJ-556 | |
System.setProperty("http.keepAlive", "false"); | |
TwitterStream s = new TwitterStreamFactory().getInstance(); | |
s.setOAuthConsumer("CONSUMER", "SECRET"); | |
s.setOAuthAccessToken(new AccessToken("ACCESSTOKEN", "SECRET")); | |
s.addListener(new StatusAdapter(){ | |
public void onStatus(Status status) { | |
System.out.println(String.format("[%s] @%s: %s" | |
, status.getCreatedAt() | |
, status.getUser().getScreenName() |
This file contains 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
class GAEAsyncTwitterImpl extends TwitterBaseImpl | |
implements Twitter { | |
public QueryResult search(Query query) throws TwitterException { | |
try { | |
return LazyEntityFactory.newQueryResult( | |
get(conf.getSearchBaseURL() + "search.json", query.asHttpParameterArray()) | |
, conf); | |
} catch (TwitterException te) { | |
if (404 == te.getStatusCode()) { | |
return new QueryResultJSONImpl(query); |
This file contains 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
public TwitterFuture getTrends() throws TwitterException { | |
final HttpResponse res = get(conf.getRestBaseURL() + "trends.json"); | |
return new TwitterFuture(){ | |
@Override | |
public void get(TwitterListener listener) throws TwitterException { | |
listener.gotTrends(new TrendsJSONImpl(res, conf)); | |
} | |
}; | |
} |
This file contains 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
import static java.util.Arrays.asList; | |
import static org.junit.Assert.assertEquals; | |
import org.json.JSONArray; | |
import org.json.JSONObject; | |
import org.junit.Test; | |
public class JSONObjectExample { | |
@Test | |
public void java_json_literal() throws Throwable{ |