private boolean handshake() throws Exception {
    URL homePage = new URL("http://mangaonweb.com/viewer.do?ctsn=" + ctsn);

    HttpURLConnection urlConn = (HttpURLConnection) homePage.openConnection();
    urlConn.connect();
    if (urlConn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return (false);

    // save the cookie
    String headerName = null;
    for (int i = 1; (headerName = urlConn.getHeaderFieldKey(i)) != null; i++) {
      if (headerName.equals("Set-Cookie")) {
        cookies = urlConn.getHeaderField(i);
      }
    }

    // save cdn and crcod
    String page = "", line;
    BufferedReader stream =
        new BufferedReader(new InputStreamReader(urlConn.getInputStream(), "UTF-8"));
    while ((line = stream.readLine()) != null) page += line;

    cdn = param(page, "cdn");
    crcod = param(page, "crcod");

    return (true);
  }
Exemple #2
0
 public static boolean isXmlFile(String filename) {
   try {
     BufferedReader f = new BufferedReader(new FileReader(filename));
     String s = f.readLine();
     boolean xml = (s != null && s.toLowerCase().startsWith("<?xml"));
     f.close();
     return xml;
   } catch (Exception eignore) {
     return false;
   }
 }
Exemple #3
0
 public static void loadDict(String strDict) {
   try {
     BufferedReader br = new BufferedReader(new FileReader(strDict));
     String line = null;
     while ((line = br.readLine()) != null) {
       int idx = line.indexOf(',');
       if (idx > 0) {
         htDict.put(line.substring(0, idx), line.substring(idx + 1));
       }
     }
   } catch (FileNotFoundException fnfe) {
     fnfe.printStackTrace(System.out);
   } catch (IOException ioe) {
     ioe.printStackTrace(System.out);
   }
 }
Exemple #4
0
 public int runCsvImport() {
   int count = 0;
   try {
     int linecnt = 0;
     String[] header = null;
     ArrayList<String> fieldsInImport = new ArrayList<String>();
     BufferedReader f =
         new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));
     String s;
     DataRecord dummyRecord = storageObject.createNewRecord();
     while ((s = f.readLine()) != null) {
       s = s.trim();
       if (s.length() == 0) {
         continue;
       }
       Vector<String> fields = splitFields(s);
       if (fields.size() > 0) {
         if (linecnt == 0) {
           // header
           header = new String[fields.size()];
           for (int i = 0; i < fields.size(); i++) {
             header[i] = fields.get(i);
             if (header[i].startsWith("#") && header[i].endsWith("#") && header.length > 2) {
               header[i] = header[i].substring(1, header[i].length() - 1).trim();
               overrideKeyField = header[i];
             }
             String[] equivFields = dummyRecord.getEquivalentFields(header[i]);
             for (String ef : equivFields) {
               fieldsInImport.add(ef);
             }
           }
         } else {
           // fields
           DataRecord r = storageObject.createNewRecord();
           for (int i = 0; i < header.length; i++) {
             String value = (fields.size() > i ? fields.get(i) : null);
             if (value != null && value.length() > 0) {
               try {
                 if (!r.setFromText(header[i], value.trim())) {
                   logImportWarning(
                       r,
                       "Value '"
                           + value
                           + "' for Field '"
                           + header[i]
                           + "' corrected to '"
                           + r.getAsText(header[i])
                           + "'");
                 }
               } catch (Exception esetvalue) {
                 logImportWarning(
                     r,
                     "Cannot set value '"
                         + value
                         + "' for Field '"
                         + header[i]
                         + "': "
                         + esetvalue.toString());
               }
             }
           }
           if (importRecord(r, fieldsInImport)) {
             count++;
           }
         }
       }
       linecnt++;
     }
     f.close();
   } catch (Exception e) {
     logInfo(e.toString());
     errorCount++;
     Logger.log(e);
     if (Daten.isGuiAppl()) {
       Dialog.error(e.toString());
     }
   }
   return count;
 }