レス数が1スレッドの最大レス数(1000件)を超えています。残念ながら投稿することができません。
ヒッキープログラミングスレ
-
一応でけた
public class MyCookieStore implements CookieStore {
HashSet<URI> uris = new HashSet<URI>();
HashMap<String, HttpCookie> cookies = new HashMap<String, HttpCookie>();
File cookiedir = null;
File uridir = null;
public MyCookieStore() {
System.out.println("MyCookieStore.Constractor");
this.cookiedir = new File(System.getProperty("user.dir"), "cookie");
if (this.cookiedir.exists() == false) this.cookiedir.mkdir();
try {
File[] files = this.cookiedir.listFiles();
for (int i = 0; i < files.length; i++) {
System.out.println("cookie["+i+"]="+files[i]);
BufferedReader reader = new BufferedReader(new FileReader(files[i]));
this.cookies.put(files[i].getName(), new HttpCookie(files[i].getName(), reader.readLine()));
reader.close();
}
this.uridir = new File(System.getProperty("user.dir"), "uri");
if (this.uridir.exists() == false) this.uridir.mkdir();
files = this.uridir.listFiles();
for (int i = 0; i < files.length; i++) {
System.out.println("uri["+i+"]="+files[i]);
BufferedReader reader = new BufferedReader(new FileReader(files[i]));
this.uris.add(new URI(reader.readLine()));
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void add(URI uri, HttpCookie cookie) {
System.out.println("MyCookieStore.add("+uri+", "+cookie+")");
try {
this.cookies.put(cookie.getName(), cookie);
PrintWriter writer = new PrintWriter(new File(this.cookiedir, cookie.getName()));
writer.print(cookie.getValue());
writer.close();
if (this.uris.add(uri)) {
writer = new PrintWriter(new File(this.uridir, "uri"+this.uris.size()));
writer.print(uri.toString());
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public List<HttpCookie> get(URI uri) {
System.out.println("MyCookieStore.get("+uri+")");
return this.getCookies();
}
public List<HttpCookie> getCookies() {
System.out.println("MyCookieStore.getCookies()");
return new Vector<HttpCookie>(this.cookies.values());
}
public List<URI> getURIs(){
System.out.println("MyCookieStore.getURIs()");
return new Vector<URI>(this.uris);
}
public boolean remove(URI uri, HttpCookie cookie) {
System.out.println("MyCookieStore.remove("+uri+", "+cookie+")");
this.cookies.remove(cookie.getName());
return true;
}
public boolean removeAll() {
System.out.println("MyCookieStore.removeAll()");
this.cookies.clear();
File[] files = this.cookiedir.listFiles();
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
return true;
}
}
|
|
掲示板管理者へ連絡
無料レンタル掲示板