Java Code Examples for java.io.BufferedWriter#write()

The following examples show how to use java.io.BufferedWriter#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployFileConfigHandler.java    From DBus with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: RetainedIntronFinder.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: Index.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 ();
    }
}
 
Example 4
Source File: Properties.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: ConfigInspectorController.java    From GreenSummer with GNU Lesser General Public License v2.1 6 votes vote down vote up
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(": ");
}
 
Example 6
Source File: FileUtils.java    From startup-os with Apache License 2.0 6 votes vote down vote up
/** 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();
  }
}
 
Example 7
Source File: XMLControlElement.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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());
  }
}
 
Example 8
Source File: WriteData.java    From swift-k with Apache License 2.0 5 votes vote down vote up
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();
	}
}
 
Example 9
Source File: ExternalCommands.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 10
Source File: CheckBaseComponentsHandler.java    From DBus with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 11
Source File: HttpsSocketFacTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 12
Source File: PerformanceThread.java    From cloudExplorer with GNU General Public License v3.0 5 votes vote down vote up
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) {
    }
}
 
Example 13
Source File: NaryTreebank.java    From pacaya with Apache License 2.0 5 votes vote down vote up
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(); 
}
 
Example 14
Source File: TaskoRun.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 15
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void writeString(FSDataOutputStream outputStream, String value)
    throws IOException {
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
      outputStream));
  writer.write(value);
  writer.close();
}
 
Example 16
Source File: FNLP2BMES.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 17
Source File: WordSimilarity.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 18
Source File: GenerateProjects.java    From MPS-extensions with Apache License 2.0 4 votes vote down vote up
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();

}
 
Example 19
Source File: SVGLoaderTemplateWriter.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeFields(BufferedWriter bw) throws IOException {
    bw.newLine();
    bw.write(HEAD_SPACE + "private static LongSparseArray<Drawable.ConstantState> sPreloadedDrawables;");
    bw.newLine();
}
 
Example 20
Source File: LYGFileIO.java    From Data_Processor with Apache License 2.0 4 votes vote down vote up
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();
}