java.io.BufferedWriter#write ( )源码实例Demo

下面列出了java.io.BufferedWriter#write ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: startup-os   文件: FileUtils.java
/** Writes a proto to zip archive. */
// TODO: Think over how to instead of writing the file to disk and then copying, and then
// deleting, write it once, directly to the Zip filesystem
public void writePrototxtToZip(Message proto, String zipFilePath, String pathInsideZip)
    throws IOException {
  String fileContent = TextFormat.printToUnicodeString(proto);
  File tempPrototxt = File.createTempFile("temp_prototxt", ".prototxt");
  BufferedWriter writer = new BufferedWriter(new FileWriter(tempPrototxt));
  writer.write(fileContent);
  writer.close();

  Map<String, String> env = new HashMap<>();
  env.put("create", "true");

  URI uri = URI.create(String.format("jar:file:%s", joinPaths(zipFilePath)));
  try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
    Files.copy(
        fileSystem.getPath(expandHomeDirectory(tempPrototxt.getPath())),
        zipfs.getPath(pathInsideZip),
        StandardCopyOption.REPLACE_EXISTING);
  } finally {
    tempPrototxt.deleteOnExit();
  }
}
 
源代码2 项目: DBus   文件: DeployFileConfigHandler.java
@Override
public void checkDeploy(BufferedWriter bw) throws Exception {
    LogCheckConfigBean lccb = AutoCheckConfigContainer.getInstance().getAutoCheckConf();
    String logType = lccb.getLogType();
    if (StringUtils.equals(logType, "filebeat")) {
        deployFilebeat(lccb, bw);
    } else if (StringUtils.equals(logType, "flume")) {
        deployFlume(lccb, bw);
    } else if (StringUtils.equals(logType, "logstash")) {
        deployLogstash(lccb, bw);
    } else {
        bw.write("日志类型错误!请检查配置项!\n");
        System.out.println("ERROR: 日志类型错误!请检查log.type配置项!");
        updateConfigProcessExit(bw);
    }
}
 
源代码3 项目: GreenSummer   文件: ConfigInspectorController.java
private void printYamlKey(String key, String previousKey, BufferedWriter theBW) throws IOException {
    int lastDot = key.lastIndexOf(".");
    if (lastDot > -1) {
        String prefix = key.substring(0, lastDot);
        // If the prefix of the previous key was different up to this point, print it,
        // else ignore it
        if (previousKey.length() <= lastDot || !previousKey.substring(0, lastDot).equals(prefix)) {
            printYamlKey(prefix, previousKey, theBW);
            theBW.newLine();
        }
        for (int i = 0; i < StringUtils.countOccurrencesOf(prefix, ".") + 1; i++) {
            theBW.write("  ");
        }
        theBW.write(key.substring(lastDot + 1));
    }
    else {
        theBW.write(key);
    }
    theBW.write(": ");
}
 
源代码4 项目: openjdk-jdk8u   文件: Properties.java
private void store0(BufferedWriter bw, String comments, boolean escUnicode)
    throws IOException
{
    if (comments != null) {
        writeComments(bw, comments);
    }
    bw.write("#" + new Date().toString());
    bw.newLine();
    synchronized (this) {
        for (Enumeration<?> e = keys(); e.hasMoreElements();) {
            String key = (String)e.nextElement();
            String val = (String)get(key);
            key = saveConvert(key, true, escUnicode);
            /* No need to escape embedded and trailing spaces for value, hence
             * pass false to flag.
             */
            val = saveConvert(val, false, escUnicode);
            bw.write(key + "=" + val);
            bw.newLine();
        }
    }
    bw.flush();
}
 
源代码5 项目: netbeans   文件: Index.java
public static void save () throws IOException {
    File dir = getCacheFolder ();
    File segments = new File (dir, "segments");
    BufferedWriter writer = new BufferedWriter (new FileWriter (segments));
    try {
        int i = 1;
        Iterator<FileObject> it = projectToCache.keySet ().iterator ();
        while (it.hasNext ()) {
            FileObject fo = it.next ();
            ProjectCache cache = projectToCache.get (fo);
            File s = new File (dir, "s" + i);
            cache.save (s);
            writer.write (fo.getPath ());
            writer.newLine ();
        }
    } finally {
        writer.close ();
    }
}
 
源代码6 项目: hmftools   文件: RetainedIntronFinder.java
public static BufferedWriter createWriter(final IsofoxConfig config)
{
    try
    {
        final String outputFileName = config.formOutputFile("retained_intron.csv");

        BufferedWriter writer = createBufferedWriter(outputFileName, false);
        writer.write("GeneId,GeneName,Chromosome,Strand,Position");
        writer.write(",Type,FragCount,SplicedFragCount,TotalDepth,TranscriptInfo");
        writer.newLine();
        return writer;
    }
    catch (IOException e)
    {
        ISF_LOGGER.error("failed to create retained intron writer: {}", e.toString());
        return null;
    }
}
 
源代码7 项目: spacewalk   文件: TaskoRun.java
private void appendLogToFile(String fileName, String logContent) {
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
        out.write(logContent);
        out.close();
    }
    catch (IOException e) {
        log.error("Unable to store log file to " + fileName);
    }
}
 
源代码8 项目: cloudExplorer   文件: PerformanceThread.java
public void performance_logger(double time, double rate, String what) {
    try {
        FileWriter frr = new FileWriter(what, true);
        BufferedWriter bfrr = new BufferedWriter(frr);
        bfrr.write("\n" + time + "," + rate);
        bfrr.close();
    } catch (Exception perf_logger) {
    }
}
 
源代码9 项目: DBus   文件: CheckBaseComponentsHandler.java
public void checkZk(BufferedWriter bw) throws Exception {
    bw.newLine();
    bw.write("check base component zookeeper start: ");
    bw.newLine();
    bw.write("============================================");
    bw.newLine();
    String[] cmd = {"/bin/sh", "-c", "jps -l | grep QuorumPeerMain"};
    Process process = Runtime.getRuntime().exec(cmd);
    Thread outThread = new Thread(new StreamRunnable(process.getInputStream(), bw));
    Thread errThread = new Thread(new StreamRunnable(process.getErrorStream(), bw));
    outThread.start();
    errThread.start();
    int exitValue = process.waitFor();
    if (exitValue != 0) process.destroyForcibly();
}
 
源代码10 项目: osp   文件: XMLControlElement.java
/**
 * Writes the DTD to a Writer.
 *
 * @param out the Writer
 */
public void writeDocType(Writer out) {
  try {
    output = new BufferedWriter(out);
    output.write(XML.getDTD(getDoctype()));
    output.flush();
    output.close();
  } catch(IOException ex) {
    OSPLog.info(ex.getMessage());
  }
}
 
源代码11 项目: swift-k   文件: WriteData.java
private void writePrimitiveArray(BufferedWriter br, DSHandle src) throws IOException,
		ExecutionException {
    // this scheme currently only works properly if the keys are strings
	Map<Comparable<?>, DSHandle> m = ((AbstractDataNode) src).getArrayValue();
	Map<Comparable<?>, DSHandle> c = new TreeMap<Comparable<?>, DSHandle>();
	c.putAll(m);
	for (DSHandle h : c.values()) {
		br.write(h.getValue().toString());
		br.newLine();
	}
}
 
源代码12 项目: semafor-semantic-parser   文件: ExternalCommands.java
public static void runExternalCommand(String command, String printFile)
{
	String s = null;
	try {
		Process p = Runtime.getRuntime().exec(command);
		PrintStream errStream=System.err;
		System.setErr(System.out);
		BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
		BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
		BufferedWriter bWriter = new BufferedWriter(new FileWriter(printFile));
		// read the output from the command
		System.out.println("Here is the standard output of the command:");
		while ((s = stdInput.readLine()) != null) {
			bWriter.write(s.trim()+"\n");
		}
		bWriter.close();
		System.out.println("Here is the standard error of the command (if any):");
		while ((s = stdError.readLine()) != null) {
			System.out.println(s);
		}
		p.destroy();
		System.setErr(errStream);
	}
	catch (IOException e) {
		System.out.println("exception happened - here's what I know: ");
		e.printStackTrace();
		System.exit(-1);
	}
}
 
源代码13 项目: jdk8u-dev-jdk   文件: HttpsSocketFacTest.java
@Override
public void handle(HttpExchange t) throws IOException {
    t.sendResponseHeaders(200, message.length());
    BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(t.getResponseBody(), "ISO8859-1"));
    writer.write(message, 0, message.length());
    writer.close();
    t.close();
}
 
源代码14 项目: pacaya   文件: NaryTreebank.java
public void writeSentencesInOneLineFormat(String outFile) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
    for (NaryTree tree : this) {
        List<String> sent = tree.getWords();
        writer.write(StringUtils.join(sent.toArray(), " "));
        writer.write("\n");
    }
    writer.close(); 
}
 
源代码15 项目: hadoop   文件: NativeAzureFileSystemBaseTest.java
private void writeString(FSDataOutputStream outputStream, String value)
    throws IOException {
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
      outputStream));
  writer.write(value);
  writer.close();
}
 
源代码16 项目: fnlp   文件: FNLP2BMES.java
static void w2BMES_Word(FNLPCorpus corpus, String file)
		throws UnsupportedEncodingException, FileNotFoundException,
		IOException {
	BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(
			new FileOutputStream(file ), "UTF-8"));
	Iterator<FNLPDoc> it1 = corpus.docs.iterator();
	while(it1.hasNext()){
		FNLPDoc doc = it1.next();
		Iterator<FNLPSent> it2 = doc.sentences.iterator();
		while(it2.hasNext()){
			FNLPSent sent = it2.next();
			for(String w:sent.words){
			
			String s = Tags.genSequence4Tags(new String[]{w});
			bout.write(s);
			String w1 = ChineseTrans.toFullWidth(w);
			if(!w1.equals(w)){
				String ss = Tags.genSequence4Tags(new String[]{w1});
				bout.write(ss);
			}
			
			}
		}

	}
	bout.close();
}
 
源代码17 项目: fnlp   文件: WordSimilarity.java
public void biList2File(String output) throws IOException {
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
    for (ArrayList<String> list : clusterResult) {
        for (String s : list) {
            bw.write(s + " ");
        }
        bw.write("\n");
    }
    bw.close();
}
 
源代码18 项目: MPS-extensions   文件: GenerateProjects.java
public static void main(String[] args) throws Exception {
    System.out.println("Generating projects for "+ projectDir.getAbsolutePath()+ " into "+ modulesXml);

    modulesXml.getParentFile().mkdirs();

    BufferedWriter w = new BufferedWriter(new FileWriter(modulesXml));

    w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<project version=\"4\">\n" +
            "  <component name=\"MPSProject\">\n" +
            "    <projectModules>");
    w.newLine();

    traverse(projectDir, w);


    w.write("    </projectModules>\n" +
            "  </component>\n" +
            "</project>");

    w.close();

}
 
源代码19 项目: SVG-Android   文件: SVGLoaderTemplateWriter.java
@Override
protected void writeFields(BufferedWriter bw) throws IOException {
    bw.newLine();
    bw.write(HEAD_SPACE + "private static LongSparseArray<Drawable.ConstantState> sPreloadedDrawables;");
    bw.newLine();
}
 
源代码20 项目: Data_Processor   文件: LYGFileIO.java
public void lygWrite(String string) throws IOException {
	BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(string),"GBK"));
	wr.write("<HEAD>"+"\n");
	wr.write("<MFR>\n"+header.MFrameRate+"\n</MFR>\n");
	System.out.println("<MFR>\n"+header.MFrameRate+"\n</MFR>\n");
	wr.write("<MHR>\n"+header.MHFrame+"\n</MHR>\n");
	System.out.println("<MHR>\n"+header.MHFrame+"\n</MHR>\n");
	wr.write("<MWR>\n"+header.MWFrame+"\n</MWR>\n");
	System.out.println("<MWR>\n"+header.MWFrame+"\n</MWR>\n");
	wr.write("<MFL>\n"+header.MFrameLeangth+"\n</MFL>\n");
	System.out.println("<MFL>\n"+header.MFrameLeangth+"\n</MFL>\n");
	//en /1sample rate /2samplesize /3 channels /4framesize  /5 framrate/bigendianture 
	wr.write("<AEN>\n"+header.SEn.toString()+"\n</AEN>\n");
	System.out.println("<AEN>\n"+header.SEn.toString()+"\n</AEN>\n");
	wr.write("<ASR>\n"+header.SSampleRate+"\n</ASR>\n");
	System.out.println("<ASR>\n"+header.SSampleRate+"\n</ASR>\n");
	wr.write("<ASS>\n"+header.SSampleSizeInBits+"\n</ASS>\n");
	System.out.println("<ASS>\n"+header.SSampleSizeInBits+"\n</ASS>\n");
	wr.write("<ACH>\n"+header.SChannels+"\n</ACH>\n");
	System.out.println("<ACH>\n"+header.SChannels+"\n</ACH>\n");
	wr.write("<AFS>\n"+header.SFrameSize+"\n</AFS>\n");
	System.out.println("<AFS>\n"+header.SFrameSize+"\n</AFS>\n");
	wr.write("<AFR>\n"+header.SFrameRate+"\n</AFR>\n");
	System.out.println("<AFR>\n"+header.SFrameRate+"\n</AFR>\n");
	wr.write("<ABE>\n"+header.SBigEndian+"\n</ABE>\n");
	System.out.println("<ABE>\n"+header.SBigEndian+"\n</ABE>\n");
	wr.write("<AFL>\n"+header.SFrameLeangth+"\n</AFL>\n");
	System.out.println("<AFL>\n"+header.SFrameLeangth+"\n</AFL>\n");
	wr.write("</HEAD>"+"\n");
	wr.write("<FRAME>"+"\n");
	wr.write("<AF>"+"\n");
	if(adataFrame!=null) {
		for(int i=0;i<adataFrame.audioArray.length;i++){
			wr.write(adataFrame.audioArray[i]+"\n");    
		}
		while(adataFrame.next!=null){
			adataFrame=adataFrame.next;
			for(int i=0;i<adataFrame.audioArray.length;i++){
				wr.write(adataFrame.audioArray[i]+"\n");    
			}

		}            	
	}
	wr.write("</AF>"+"\n");
	wr.write("<MF>"+"\n");
	long fr=0;
	if(mdataframe != null) {
		for (int i = 0; i < header.MHFrame; i++){
			for (int j = 0; j < header.MWFrame; j++){
				wr.write(mdataframe.image.getRGB(j, i)+"\n");		
			}
		}
		fr++;
		wr.write(fr+"\n");
		while(mdataframe.next!=null){
			mdataframe=mdataframe.next;
			for (int i = 0; i < header.MHFrame; i++){
				for (int j = 0; j < header.MWFrame; j++){
					wr.write(mdataframe.image.getRGB(j, i)+"\n");		
				}
			}
			fr++;
			wr.write(fr+"\n");
		}
	}
	wr.write("</MF>"+"\n");
	wr.write("</FRAME>"+"\n");
	wr.flush();
	wr.close();
}