List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:Main.java
public static File createTempDir() throws IOException { File temp;/* w ww . j av a2 s. co m*/ temp = File.createTempFile("encfs-java-tmp", Long.toString(System.nanoTime())); if (!temp.delete()) { throw new IOException("Could not delete temporary file " + temp.getAbsolutePath()); } if (!temp.mkdir()) { throw new IOException("Could not create temporary directory"); } return temp; }
From source file:Main.java
public static File WriteStringToFile(String str) { File tmpFile = null;/*from w w w . j av a 2 s . c o m*/ try { tmpFile = File.createTempFile("z4-", ".tmp"); BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile)); out.write(str); out.close(); } catch (IOException e) { e.printStackTrace(); } return tmpFile; }
From source file:Main.java
private static File createTempFile(String filename) { try {/* w w w .j ava 2 s.c om*/ int dotIndex = filename.lastIndexOf("."); String prefix = filename.substring(0, dotIndex); String suffix = filename.substring(dotIndex + 1); File temp = File.createTempFile(prefix, suffix); temp.deleteOnExit(); return temp; } catch (Exception e) { throw new RuntimeException("Could not create temp file: " + filename, e); } }
From source file:Main.java
public static File WriteStreamToFile(InputStream resStream) { try {/*from w w w . ja va2 s .c om*/ byte[] bytes = new byte[resStream.available()]; File tmpFile = File.createTempFile("z4-", ".tmp"); tmpFile.deleteOnExit(); DataInputStream dis = new DataInputStream(resStream); dis.readFully(bytes); FileOutputStream foutStream = new FileOutputStream(tmpFile.getPath()); foutStream.write(bytes); foutStream.close(); dis.close(); return tmpFile; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getMotherboardSN() { String result = ""; try {/*from w ww . j a v a 2 s . c o m*/ File file = File.createTempFile("realhowto", ".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + " exit for ' do the first cpu only! \n" + "Next \n"; fw.write(vbs); fw.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch (Exception e) { e.printStackTrace(); } return result.trim(); }
From source file:Main.java
public static String getHardDiskSN(String drive) { String result = ""; try {//from w w w. j av a2s . com File file = File.createTempFile("realhowto", ".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n" + "Wscript.Echo objDrive.SerialNumber"; // see note fw.write(vbs); fw.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch (Exception e) { e.printStackTrace(); } return result.trim(); }
From source file:fr.jayasoft.ivy.Main.java
public static void main(String[] args) throws Exception { Options options = getOptions();/* w w w .j a v a 2 s.c o m*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("?")) { usage(options); return; } if (line.hasOption("debug")) { Message.init(new DefaultMessageImpl(Message.MSG_DEBUG)); } else if (line.hasOption("verbose")) { Message.init(new DefaultMessageImpl(Message.MSG_VERBOSE)); } else if (line.hasOption("warn")) { Message.init(new DefaultMessageImpl(Message.MSG_WARN)); } else if (line.hasOption("error")) { Message.init(new DefaultMessageImpl(Message.MSG_ERR)); } else { Message.init(new DefaultMessageImpl(Message.MSG_INFO)); } boolean validate = line.hasOption("novalidate") ? false : true; Ivy ivy = new Ivy(); ivy.addAllVariables(System.getProperties()); if (line.hasOption("m2compatible")) { ivy.setVariable("ivy.default.configuration.m2compatible", "true"); } configureURLHandler(line.getOptionValue("realm", null), line.getOptionValue("host", null), line.getOptionValue("username", null), line.getOptionValue("passwd", null)); String confPath = line.getOptionValue("conf", ""); if ("".equals(confPath)) { ivy.configureDefault(); } else { File conffile = new File(confPath); if (!conffile.exists()) { error(options, "ivy configuration file not found: " + conffile); } else if (conffile.isDirectory()) { error(options, "ivy configuration file is not a file: " + conffile); } ivy.configure(conffile); } File cache = new File( ivy.substitute(line.getOptionValue("cache", ivy.getDefaultCache().getAbsolutePath()))); if (!cache.exists()) { cache.mkdirs(); } else if (!cache.isDirectory()) { error(options, cache + " is not a directory"); } String[] confs; if (line.hasOption("confs")) { confs = line.getOptionValues("confs"); } else { confs = new String[] { "*" }; } File ivyfile; if (line.hasOption("dependency")) { String[] dep = line.getOptionValues("dependency"); if (dep.length != 3) { error(options, "dependency should be expressed with exactly 3 arguments: organisation module revision"); } ivyfile = File.createTempFile("ivy", ".xml"); ivyfile.deleteOnExit(); DefaultModuleDescriptor md = DefaultModuleDescriptor .newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller", "working")); DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true); for (int i = 0; i < confs.length; i++) { dd.addDependencyConfiguration("default", confs[i]); } md.addDependency(dd); XmlModuleDescriptorWriter.write(md, ivyfile); confs = new String[] { "default" }; } else { ivyfile = new File(ivy.substitute(line.getOptionValue("ivy", "ivy.xml"))); if (!ivyfile.exists()) { error(options, "ivy file not found: " + ivyfile); } else if (ivyfile.isDirectory()) { error(options, "ivy file is not a file: " + ivyfile); } } ResolveReport report = ivy.resolve(ivyfile.toURL(), null, confs, cache, null, validate, false, true, line.hasOption("useOrigin"), null); if (report.hasError()) { System.exit(1); } ModuleDescriptor md = report.getModuleDescriptor(); if (confs.length == 1 && "*".equals(confs[0])) { confs = md.getConfigurationsNames(); } if (line.hasOption("retrieve")) { String retrievePattern = ivy.substitute(line.getOptionValue("retrieve")); if (retrievePattern.indexOf("[") == -1) { retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]"; } ivy.retrieve(md.getModuleRevisionId().getModuleId(), confs, cache, retrievePattern, null, null, line.hasOption("sync"), line.hasOption("useOrigin")); } if (line.hasOption("cachepath")) { outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", "ivycachepath.txt")); } if (line.hasOption("revision")) { ivy.deliver(md.getResolvedModuleRevisionId(), ivy.substitute(line.getOptionValue("revision")), cache, ivy.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")), ivy.substitute(line.getOptionValue("status", "release")), null, new DefaultPublishingDRResolver(), validate); if (line.hasOption("publish")) { ivy.publish(md.getResolvedModuleRevisionId(), ivy.substitute(line.getOptionValue("revision")), cache, ivy.substitute(line.getOptionValue("publishpattern", "distrib/[type]s/[artifact]-[revision].[ext]")), line.getOptionValue("publish"), ivy.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")), validate); } } if (line.hasOption("main")) { invoke(ivy, cache, md, confs, line.getOptionValue("main"), line.getOptionValues("args")); } } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); usage(options); } }
From source file:net.bpelunit.util.FileUtil.java
public static File createTempDirectory() throws IOException { File tmp = File.createTempFile("bpelunit", ""); tmp.delete();//w ww. j av a 2s . c om tmp.mkdir(); return tmp; }
From source file:Main.java
public static File saveBitmap2file(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); File imageFile = null;/* w w w. j a va 2s. c om*/ try { imageFile = File.createTempFile("tempImage" + System.currentTimeMillis(), ".png"); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fstream = null; try { fstream = new FileOutputStream(imageFile); BufferedOutputStream bStream = new BufferedOutputStream(fstream); bStream.write(byteArray); if (bStream != null) { bStream.close(); } } catch (IOException e) { e.printStackTrace(); } return imageFile; }
From source file:Main.java
public static String getThumbnailImage(String path, int targetWidth) { Bitmap scaleImage = decodeScaleImage(path, targetWidth, targetWidth); try {//w w w . j a v a 2 s.com File file = File.createTempFile("image", ".jpg"); FileOutputStream fileOutputStream = new FileOutputStream(file); scaleImage.compress(Bitmap.CompressFormat.JPEG, 60, fileOutputStream); fileOutputStream.close(); return file.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); return path; } }