public FitsImage factory(String file) { if (first) { first = false; if (Settings.has("FilePrefix")) { prefix = Settings.get("FilePrefix"); havePrefix = true; } } if (havePrefix) { file = prefix + file; } try { return new FitsImage(file); } catch (Exception e) { e.printStackTrace(); throw new Error("Irrecoverable FITS error for file: " + file); } }
/** Copy a URL to a local file */ public static void getURL(String url, String file) throws Exception { int timeout = 1200000; // Default to 15 seconds. if (Settings.has("SIAImageTimeout")) { try { timeout = Integer.parseInt(Settings.get("SIAImageTimeout")); } catch (Exception e) { } } try { java.net.URL u = new java.net.URL(url); java.net.URLConnection conn = u.openConnection(); conn.setReadTimeout(60000); // SDSS required this sometimes. if (url.substring(0, 3).toLowerCase().equals("htt")) { conn.setRequestProperty("accept", "*/*"); } InputStream bi = conn.getInputStream(); OutputStream bo = new java.io.FileOutputStream(file); byte[] buffer = new byte[32768]; int len; while ((len = bi.read(buffer)) > 0) { bo.write(buffer, 0, len); } bi.close(); bo.close(); } catch (java.net.SocketTimeoutException e) { System.err.println("Timeout querying SIAP URL " + url + "\n"); throw new Error("\nTimeout querying SIAP URL " + url + "\n"); } catch (Exception e) { throw new Error("Unable to do IO over network:" + e); } }