4 import java.io.IOException;
5 import java.util.ArrayList;
7 import org.apache.commons.io.FileUtils;
8 import org.apache.commons.lang.StringUtils;
11 * Microsoft Internete Explorer用cookie.
14 public class CookieWinMsIe extends Cookie {
17 * IE7/IE8/IE9 から user_session を取得。<br/>
18 * エラーが起こった場合、例外を投げずに空文字を返す
20 * @return user_session
23 public String getUserSessionString() throws IOException {
25 final String userProfile = System.getenv("USERPROFILE");
26 if (StringUtils.isEmpty(userProfile)) {
27 throw new IOException("USERPROFILE not found");
30 final List<File> searchDirs = new ArrayList<>();
31 // http://msdn.microsoft.com/en-us/library/aa385326(v=VS.85).aspx
32 searchDirs.add(new File(userProfile + "\\AppData\\Roaming\\Microsoft\\Windows\\Cookies\\Low\\"));
33 searchDirs.add(new File(userProfile + "\\AppData\\Roaming\\Microsoft\\Windows\\Cookies\\"));
35 searchDirs.add(new File(userProfile + "\\Cookies\\"));
37 return getUserSessionFromDir("MS932", searchDirs.toArray(new File[0]));