Skip to content

Instantly share code, notes, and snippets.

View HelloResource.java
package test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
// http://localhost:8080/JerseySample/sample/hello?name=aaa&age=100
@Path("/hello")
public class HelloResource {
@daichan4649
daichan4649 / TestServlet.java
Last active Aug 29, 2015
tomcat7 basic authentication
View TestServlet.java
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// logon user name
final String userName = request.getUserPrincipal().getName();
PrintWriter out = response.getWriter();
out.println(String.format("doGet(%s)", userName));
out.flush();
out.close();
@daichan4649
daichan4649 / IpListServlet.java
Created May 29, 2014
アクセスログ保存/一覧表示 (jQuery, JSON, JavaEE6)
View IpListServlet.java
package test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@daichan4649
daichan4649 / PropertyUtil.java
Last active Aug 29, 2015
Servletでのプロパティファイル読み書き
View PropertyUtil.java
public class PropertyUtil {
private static final String PROPERTY_FILE_TEST = "test.properties";
public static void setTestPropertyValue(ServletContext context, String key, String value) {
setPropertyValue(context, PROPERTY_FILE_TEST, key, value);
}
public static String getTestPropertyValue(ServletContext context, String key) {
return getPropertyValue(context, PROPERTY_FILE_TEST, key);
@daichan4649
daichan4649 / ZipUtil.java
Last active Aug 29, 2015
unzip (for Java)
View ZipUtil.java
public static void unzip(String zipFilePath, File dstDir) {
try {
final ZipFile zipFile = new ZipFile(zipFilePath);
Enumeration<? extends ZipEntry> enumZip = zipFile.entries();
while (enumZip.hasMoreElements()) {
final ZipEntry zipEntry = enumZip.nextElement();
// 出力先設定
File dstFile = new File(dstDir, zipEntry.getName());
if (dstFile.isDirectory()) {
@daichan4649
daichan4649 / Util.java
Last active Aug 29, 2015
クラスパス内ファイルのフルパス取得
View Util.java
// クラスパスルートからの相対パスを指定
private static final String relativePath = "/resources/aaa.txt";
private String getRealResourcePath(String relativePath) {
return getClass().getClassLoader().getResource(relativePath).getPath();
}
@daichan4649
daichan4649 / DebugUtil.java
Created Dec 9, 2014
JavaEE 環境でクラスパス配下のファイルを文字列として読み込む(JSON等)
View DebugUtil.java
// dir name(class pathをルートとする相対パス)
private static final String DIR_NAME = "json";
private static final String FILE_NAME = "test.json";
public static String createJsonText(Class<? extends HttpServlet> clazz) {
return createJsonText(clazz, DIR_NAME, FILE_NAME);
}
public static String createJsonText(Class<? extends HttpServlet> clazz, String dirName, String fileName) {
String dirPath = clazz.getClassLoader().getResource(dirName).getPath();
@daichan4649
daichan4649 / JsonUtil.java
Created Dec 9, 2014
gson sample (JSON -> model)
View JsonUtil.java
public interface JsonModel {
// model
}
public class JsonUtil {
@SuppressWarnings("unchecked")
public static <T> T fromJson(String jsonText, Class<? extends JsonModel> T) {
Gson gson = new Gson();
return (T) gson.fromJson(jsonText, T);
}
View MainActivity.java
package test.handler;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
View CustomImageView.java
package test.fragment.list;
import test.fragment.list.ImageFactory.Type;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;
You can’t perform that action at this time.