List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out)
From source file:Main.java
/** * Writes the current app logcat to a file. * * @param filename The filename to save it as * @throws IOException/*from w ww .j a va 2s. co m*/ */ public static void writeLogcat(String filename) throws IOException { String[] args = { "logcat", "-v", "time", "-d" }; Process process = Runtime.getRuntime().exec(args); InputStreamReader input = new InputStreamReader(process.getInputStream()); OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(filename)); BufferedReader br = new BufferedReader(input); BufferedWriter bw = new BufferedWriter(output); String line; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); } bw.close(); output.close(); br.close(); input.close(); }
From source file:com.kloudtek.buildmagic.tools.createinstaller.deb.CopyrightList.java
public void write(DataBuffer copyright, CreateDebTask task) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(copyright)); writer.write("Format: http://dep.debian.net/deps/dep5\n"); if (task.getUpstreamName() != null) { writer.write("Upstream-Name: " + task.getUpstreamName() + " \n"); }//from ww w . ja va 2s . com if (task.getUpstreamUrl() != null) { writer.write("Source: " + task.getUpstreamUrl() + " \n"); } writer.write("\n"); for (Copyright cr : this) { writer.write("Files: "); if (cr.getFiles() != null) { writer.write("*"); } else { writer.write(cr.getFiles()); } boolean first = true; for (CopyrightAuthor author : cr.getAuthors()) { if (first) { writer.write("\nCopyright: "); first = false; } else { writer.write("\n "); } String year = author.getYear() != null ? author.getYear() : getCurrentYear(); writer.write(year); writer.write(" "); String name = author.getName() != null ? author.getName() : task.getMaintName(); writer.write(name); String email = author.getEmail() != null ? author.getEmail() : task.getMaintEmail(); writer.write(" <"); writer.write(email); writer.write(">\nLicense: "); writer.write(cr.getLicense()); writer.write("\n "); String licTxt = FileUtils.readFileToString(cr.getLicenseFile()); licTxt = licTxt.replace("\n\n", "\n.\n").replace("\n", "\n "); writer.write(licTxt); writer.write("\n\n"); } } writer.close(); }
From source file:edu.jhu.cvrg.timeseriesstore.opentsdb.AnnotationManager.java
public static String createIntervalAnnotation(String urlString, long startEpoch, long endEpoch, String tsuid, String description, String notes) { urlString = urlString + API_METHOD;//from w w w . jav a 2s.com String result = ""; try { HttpURLConnection httpConnection = TimeSeriesUtility.openHTTPConnectionPOST(urlString); OutputStreamWriter wr = new OutputStreamWriter(httpConnection.getOutputStream()); JSONObject requestObject = new JSONObject(); requestObject.put("startTime", startEpoch); requestObject.put("endTime", endEpoch); requestObject.put("tsuid", tsuid); requestObject.put("description", description); requestObject.put("notes", notes); wr.write(requestObject.toString()); wr.close(); result = TimeSeriesUtility.readHttpResponse(httpConnection); } catch (IOException e) { e.printStackTrace(); return null; } catch (OpenTSDBException e) { e.printStackTrace(); result = String.valueOf(e.responseCode); } catch (JSONException e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Get the default charset//from w ww . java2s. c o m * * @return The default charset */ public static final String getDefaultCharsetName() throws Exception { String defaultCharset; try { // Try with jdk 1.5 method, if we are using a 1.5 jdk :) Method method = Charset.class.getMethod("defaultCharset", new Class[0]); defaultCharset = ((Charset) method.invoke(null, new Object[0])).name(); } catch (NoSuchMethodException nsme) { defaultCharset = new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); } catch (InvocationTargetException ite) { defaultCharset = new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); } catch (IllegalAccessException iea) { defaultCharset = new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); } catch (RuntimeException e) { // fall back to old method defaultCharset = new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); } return defaultCharset; }
From source file:net.sf.zekr.engine.theme.Theme.java
/** * Save a ThemeData configuration file.//from ww w . j a v a 2s . c o m * * @param td theme data object to be stored to the disk * @throws IOException */ public static void save(ThemeData td) throws IOException { OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream(Naming.getThemePropsDir() + "/" + td.fileName)); LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); map.put("name", td.name); map.put("author", td.author); map.put("version", td.version); map.putAll(td.props); ConfigUtils.write(new MapConfiguration(map), osw); // ConfigurationUtils.dump(new MapConfiguration(map), new PrintWriter(osw)); IOUtils.closeQuietly(osw); }
From source file:com.amalto.workbench.utils.FileProvider.java
public static IFile createdTempFile(String templateString, String fileNameWithExtension, String charSet) { IFile file = null;//www . j av a 2s. c om if (templateString != null) { try { Project project = ProjectManager.getInstance().getCurrentProject(); IProject prj = ResourceUtils.getProject(project); file = prj.getFile(new Path("temp/" + fileNameWithExtension)); //$NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OutputStreamWriter outputStreamWriter = null; if ((charSet == null) || (charSet.trim().isEmpty())) { outputStreamWriter = new OutputStreamWriter(outputStream); } else { outputStreamWriter = new OutputStreamWriter(outputStream, charSet); } outputStreamWriter.write(templateString); outputStreamWriter.flush(); outputStreamWriter.close(); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); if (file.exists()) { file.setContents(inputStream, true, false, null); } else { file.create(inputStream, true, null); } inputStream.close(); } catch (Exception e) { log.error(e.getMessage(), e); } } return file; }
From source file:com.jredrain.base.utils.CommandUtils.java
public static File createShellFile(String command, String shellFileName) { String dirPath = IOUtils.getTempFolderPath(); File dir = new File(dirPath); if (!dir.exists()) dir.mkdirs();/*from w w w . j a v a2 s . c o m*/ String tempShellFilePath = dirPath + File.separator + shellFileName + ".sh"; File shellFile = new File(tempShellFilePath); try { if (!shellFile.exists()) { PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempShellFilePath))); out.write("#!/bin/bash\n" + command); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } finally { return shellFile; } }
From source file:dualcontrol.DualControlDigest.java
public static byte[] getBytes(char[] chars) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(baos); writer.write(chars);/*from ww w. j av a 2 s.c om*/ writer.close(); return baos.toByteArray(); }
From source file:examples.echo.java
public static final void echoTCP(String host) throws IOException { EchoTCPClient client = new EchoTCPClient(); BufferedReader input, echoInput; PrintWriter echoOutput;//from w ww. java2 s . co m String line; // We want to timeout if a response takes longer than 60 seconds client.setDefaultTimeout(60000); client.connect(host); System.out.println("Connected to " + host + "."); input = new BufferedReader(new InputStreamReader(System.in)); echoOutput = new PrintWriter(new OutputStreamWriter(client.getOutputStream()), true); echoInput = new BufferedReader(new InputStreamReader(client.getInputStream())); while ((line = input.readLine()) != null) { echoOutput.println(line); System.out.println(echoInput.readLine()); } client.disconnect(); }
From source file:com.ms.commons.test.classloader.util.CLFileUtil.java
public static void copyAndProcessFileContext(URL url, File newFile, String encoding, Processor processor) { try {//from w w w. ja v a2s . com if (processor == null) { processor = DEFAULT_PROCESSOR; } if (!newFile.exists()) { String fileContext = readUrlToString(url, null); if (encoding == null) { if (FileUtil.convertURLToFilePath(url).endsWith(".xml") && fileContext.contains("\"UTF-8\"")) { encoding = "UTF-8"; fileContext = readUrlToString(url, "UTF-8"); } } (new File(getFilePath(newFile.getPath()))).mkdirs(); Writer writer; if (encoding == null) { writer = new OutputStreamWriter(new FileOutputStream(newFile)); } else { writer = new OutputStreamWriter(new FileOutputStream(newFile), encoding); } try { writer.write(processor.process(fileContext)); writer.flush(); } finally { writer.close(); } } } catch (Exception e) { throw new RuntimeException(e); } }