private void fetchOne(boolean examine, boolean save, YouAreEll yrl, InputStream is) { logger.entering(examine); logger.entering(save); logger.entering(yrl); if (examine) is = new DelimitedBufferedInputStream(is, '<', '>'); BufferedOutputStream bos = null; WebFile wf = null; if (save) { wf = new WebFile(yrl, args); bos = wf.getBOS(); if (bos == null) save = false; } if (save || examine) { if (!examineORsave(yrl, is, bos, examine, save, yrl.getURL())) { logger.severe("examineORsave failed"); } } if (bos != null) { try { bos.close(); if (args.SetLastModified) wf.getFile().setLastModified(yrl.getLastModified()); } catch (IOException e) { logger.throwing(e); } } if (examine) { try { is.close(); } catch (IOException e) { logger.throwing(e); } } }
/* ** read from an input stream, optionally write to an output stream, and ** optionally look at all the URL's found in the input stream. */ private boolean examineORsave( YouAreEll yrl, InputStream is, BufferedOutputStream bos, boolean examine, boolean save, String url) { logger.entering(is); logger.entering(bos); logger.entering(new Boolean(examine)); logger.entering(new Boolean(save)); logger.entering(url); try { int c; int read = 0; int written = 0; int content_length = yrl.getContentLength(); int ten_percent = content_length > 0 ? content_length / 10 : 0; int count = 1; boolean percent = args.SaveProgress && save && ten_percent > 0; boolean spin = args.SaveProgress && save && ten_percent == 0; long start = new java.util.Date().getTime(); if (percent) System.out.print("0.."); if (spin) System.out.print("|"); while ((c = is.read()) != -1) { if (save) { bos.write((char) c); written++; if (percent && count < 10 && written > count * ten_percent) { System.out.print(count * 10 + ".."); count++; } else if (spin && written % 1000 == 0) { // System.out.println (count); // System.out.println (count % 4); System.out.print("\b" + "|/-\\".charAt(count % 4)); count++; } } read++; } long stop = new java.util.Date().getTime(); if (percent) System.out.println("100"); if (spin) System.out.println(""); if (spin || percent) { long seconds = (stop - start) / 1000; long BPS = read / (seconds == 0 ? 1 : seconds); if (BPS > 1000000000000000L) System.out.println(BPS / 1000000000000000L + " EBps"); else if (BPS > 1000000000000L) System.out.println(BPS / 1000000000000L + " TBps"); else if (BPS > 1000000000) System.out.println(BPS / 1000000000 + " GBps"); else if (BPS > 1000000) System.out.println(BPS / 1000000 + " MBps"); else if (BPS > 1000) System.out.println(BPS / 1000 + " KBps"); else System.out.println(BPS + " Bps"); } if (save) snooze(args.PauseAfterSave); // logger.finest ("bytes read: " + read); // logger.finest ("bytes written: " + written); if (examine) addToURLs(url, ((DelimitedBufferedInputStream) is).getStrings()); } catch (IOException e) { logger.throwing(e); return (false); } return (true); }