private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry, String name) throws IOException, FileNotFoundException { if (fileEntry == null) fileEntry = zip.getEntry(name); if (fileEntry == null) throw new FileNotFoundException("Can't find " + name + " in " + zip.getName()); File outFile = new File(sGREDir, name); if (outFile.lastModified() == fileEntry.getTime() && outFile.length() == fileEntry.getSize()) return false; File dir = outFile.getParentFile(); if (!dir.exists()) dir.mkdirs(); InputStream fileStream; fileStream = zip.getInputStream(fileEntry); OutputStream outStream = new FileOutputStream(outFile); while (fileStream.available() > 0) { int read = fileStream.read(buf, 0, buf.length); outStream.write(buf, 0, read); } fileStream.close(); outStream.close(); outFile.setLastModified(fileEntry.getTime()); return true; }
static void genclass(DelegatorGenerator dg, Class intfcl, String fqcn, File srcroot) throws IOException { File genDir = new File(srcroot, dirForFqcn(fqcn)); if (!genDir.exists()) { System.err.println( JdbcProxyGenerator.class.getName() + " -- creating directory: " + genDir.getAbsolutePath()); genDir.mkdirs(); } String fileName = CodegenUtils.fqcnLastElement(fqcn) + ".java"; Writer w = null; try { w = new BufferedWriter(new FileWriter(new File(genDir, fileName))); dg.writeDelegator(intfcl, fqcn, w); w.flush(); System.err.println("Generated " + fileName); } finally { try { if (w != null) w.close(); } catch (Exception e) { e.printStackTrace(); } } }
/** * Constructor * * @throws IOException */ public JustAnotherPackageManager(Reporter reporter, Platform platform, File homeDir, File binDir) throws IOException { this.platform = platform; this.reporter = reporter; this.homeDir = homeDir; if (!homeDir.exists() && !homeDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + homeDir); repoDir = IO.getFile(homeDir, "repo"); if (!repoDir.exists() && !repoDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + repoDir); commandDir = new File(homeDir, COMMANDS); serviceDir = new File(homeDir, SERVICE); commandDir.mkdir(); serviceDir.mkdir(); service = new File(repoDir, SERVICE_JAR_FILE); if (!service.isFile()) init(); this.binDir = binDir; if (!binDir.exists() && !binDir.mkdirs()) throw new IllegalArgumentException("Could not create bin directory " + binDir); }
public static void main(final String[] args) { File logdir = new File(LOG_DIR); if (!logdir.exists()) logdir.mkdirs(); File log = new File(logdir, "client.log"); // redirect all console output to the file try { PrintStream out = new PrintStream(new FileOutputStream(log, true), true); out.format("[%s] ===== Client started =====%n", timestampf.format(new Date())); System.setOut(out); System.setErr(out); } catch (FileNotFoundException e) { e.printStackTrace(); } /* Set up the error handler as early as humanly possible. */ ThreadGroup g = new ThreadGroup("Haven main group"); String ed; if (!(ed = Utils.getprop("haven.errorurl", "")).equals("")) { try { final haven.error.ErrorHandler hg = new haven.error.ErrorHandler(new java.net.URL(ed)); hg.sethandler( new haven.error.ErrorGui(null) { public void errorsent() { hg.interrupt(); } }); g = hg; } catch (java.net.MalformedURLException e) { } } Thread main = new HackThread( g, new Runnable() { public void run() { main2(args); } }, "Haven main thread"); main.start(); }
public static void storeImage(BufferedImage image, String s) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); f.mkdirs(); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("gif") && !ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
/** * @param data * @param target * @throws Exception * @throws IOException */ public String createService(ServiceData data) throws Exception, IOException { File sdir = new File(serviceDir, data.name); if (!sdir.exists() && !sdir.mkdirs()) { throw new IOException("Could not create directory " + data.sdir); } data.sdir = sdir.getAbsolutePath(); File lock = new File(data.sdir, LOCK); data.lock = lock.getAbsolutePath(); if (data.work == null) data.work = new File(data.sdir, "work").getAbsolutePath(); if (data.user == null) data.user = platform.user(); if (data.user == null) data.user = "******"; new File(data.work).mkdir(); if (data.log == null) data.log = new File(data.sdir, "log").getAbsolutePath(); // TODO // if (Data.validate(data) != null) // return "Invalid service data: " + Data.validate(data); if (service == null) throw new RuntimeException( "Missing biz.aQute.jpm.service in repo, should have been installed by init, try reiniting"); data.serviceLib = service.getAbsolutePath(); platform.chown(data.user, true, new File(data.sdir)); String s = platform.createService(data, null, false); if (s == null) storeData(new File(data.sdir, "data"), data); return s; }