當前位置: 首頁>>代碼示例>>Java>>正文


Java Writer.flush方法代碼示例

本文整理匯總了Java中java.io.Writer.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java Writer.flush方法的具體用法?Java Writer.flush怎麽用?Java Writer.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.Writer的用法示例。


在下文中一共展示了Writer.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: outputResults

import java.io.Writer; //導入方法依賴的package包/類
protected final void outputResults() throws IOException {
  // Begin writing output file.
  FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
  Writer writer = src.openWriter();

  // Output table at top showing components by category.
  outputCategories(writer);

  // Components are already sorted.
  for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
    ComponentInfo component = entry.getValue();
    outputComponent(writer, component);
  }

  // Close output file
  writer.flush();
  writer.close();
  messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:20,代碼來源:DocumentationGenerator.java

示例2: write

import java.io.Writer; //導入方法依賴的package包/類
/**
 * Write the encryption key container to the writer.
 *
 * @param out
 *          Output writer.
 */
public void write(Writer out) throws IOException {
  Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create();

  JsonObject data = new JsonObject();
  data.addProperty("version", CURRENT_VERSION);

  JsonArray keys = new JsonArray();
  for (Entry<KeyLookup,Map<Integer,KeyWithVersion>> entry : encryptionKeys.entrySet()) {
    for (KeyWithVersion keyData : entry.getValue().values()) {
      JsonObject key = new JsonObject();
      if (entry.getKey().attribute != null) {
        key.addProperty("attribute", entry.getKey().attribute);
      }
      key.addProperty("id", entry.getKey().id);
      key.addProperty("version", keyData.version);
      key.addProperty("key", Base64.getEncoder().encodeToString(keyData.key));
      keys.add(key);
    }
  }
  data.add("keys", keys);

  gson.toJson(data, out);
  out.flush();
}
 
開發者ID:mit-ll,項目名稱:PACE,代碼行數:31,代碼來源:LocalEncryptionKeyContainer.java

示例3: writeTo

import java.io.Writer; //導入方法依賴的package包/類
public void writeTo(OutputStream stream) {
    try {
        Writer writer = new OutputStreamWriter(stream, "UTF-8");
        doWriteTo(writer, "UTF-8");
        writer.flush();
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,代碼來源:XmlTransformer.java

示例4: install

import java.io.Writer; //導入方法依賴的package包/類
@Override
public void install(@NotNull ToolMetadata version, @NotNull Writer writer) throws Exception
{
    String installDir = findInstallDir();
    if (installDir == null)
    {
        throw new Exception("Must set " + envVar() + " environment variable (and ensure it's a valid directory).");
    }
    File dir = new File(installDir);
    if (dir.exists() && !IO.cleanDir(dir))
    {
        throw new Exception("Could not remove existent directory!");
    }
    //noinspection ResultOfMethodCallIgnored
    dir.mkdirs();

    writer.write("Downloading zip...\n");
    writer.flush();
    File zipFile = new File(dir, id() + "-" + version.getVersion() + ".zip");
    IO.download(version.getZipUrl(), zipFile, (1024 * 1024), totalDownload ->
    {
        try
        {
            writer.write(convertSize(totalDownload) + " ...\n");
            writer.flush();
        }
        catch (IOException ignored)
        {
        }
    });

    writer.write("Extracting zip...\n");
    writer.flush();
    IO.extract(zipFile, dir);
    //noinspection ResultOfMethodCallIgnored
    zipFile.delete();
    IO.ensureNotRoot(dir);
    writer.write("Done! Run '" + versionCmd() + "'.\n");
}
 
開發者ID:miche-atucha,項目名稱:devenv,代碼行數:40,代碼來源:CoreToolProvider.java

示例5: copyData

import java.io.Writer; //導入方法依賴的package包/類
protected void copyData(InputStream  inputStream,
                        OutputStream outputStream)
throws IOException
{
    Reader reader = new BufferedReader(new InputStreamReader(inputStream));
    Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));

    copyData(reader, writer);

    writer.flush();
    outputStream.flush();
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:13,代碼來源:DataEntryRewriter.java

示例6: createFile

import java.io.Writer; //導入方法依賴的package包/類
/**
 * create the real file to be compiled
 */
private void createFile(String packageName, String enclosingName, String[] permissions, String methodName, String returnType) {
    try {
        Calendar calendar = Calendar.getInstance();
        String classPostfix = "" + (calendar.get(Calendar.MINUTE) + 100) + (calendar.get(Calendar.SECOND) + 100) + (calendar.get(Calendar.MILLISECOND) + 1000);
        JavaFileObject jfo = mFiler.createSourceFile(packageName + ".AutoCreate" + classPostfix, new Element[]{});
        Writer writer = jfo.openWriter();
        writer.write(CodeCreator.brewCodeNoCallback(packageName, enclosingName, permissions, classPostfix, methodName, returnType));
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
開發者ID:2017398956,項目名稱:AbcPermission,代碼行數:18,代碼來源:GetPermissionsProcessor.java

示例7: executeTerraform

import java.io.Writer; //導入方法依賴的package包/類
/**
 * Execute the given Terraform commands. Note there is no concurrency check for
 * now.
 */
private void executeTerraform(final Subscription subscription, final Writer out, final String[][] commands,
		final String... additionalParameters) throws InterruptedException, IOException {
	final AtomicInteger step = new AtomicInteger(0);
	// Reset the current step
	for (final String[] command : commands) {
		// Next step, another transaction
		runner.nextStep("service:prov:test:account", t -> t.setStep(TerraformStep.values()[step.get()]));

		final int code = executeTerraform(subscription, out, ArrayUtils.addAll(command, additionalParameters));
		if (code == 0) {
			// Nothing wrong, no change, only useless to go further
			log.info("Terraform paused for {} ({}) : {}", subscription.getId(), subscription, code);
			out.write("Terraform exit code " + code + " -> no need to continue");
			break;
		}
		if (code != 2) {
			// Something goes wrong
			log.error("Terraform failed for {} ({}) : {}", subscription.getId(), subscription, code);
			out.write("Terraform exit code " + code + " -> aborted");
			throw new BusinessException("aborted");
		}
		out.flush();

		// Code is correct, proceed the next command
		step.incrementAndGet();
	}
}
 
開發者ID:ligoj,項目名稱:plugin-prov,代碼行數:32,代碼來源:TerraformResource.java

示例8: flushBuffer

import java.io.Writer; //導入方法依賴的package包/類
private void flushBuffer(File logFile) {
    if (logBuffer.isEmpty()) {
        try {
            synchronized (this) {
                wait(25000); // Wait for next message
            }
            Thread.sleep(5); // Buffer for 5ms to reduce back and forth between disk
        } catch (InterruptedException ignore) {
        }
    }
    try {
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile, true), StandardCharsets.UTF_8), 1024);
        Date now = new Date();
        String consoleDateFormat = new SimpleDateFormat("HH:mm:ss ").format(now);
        String fileDateFormat = new SimpleDateFormat("Y-M-d HH:mm:ss ").format(now);
        int count = 0;
        while (!logBuffer.isEmpty()) {
            String message = logBuffer.poll();
            if (message != null) {
                writer.write(fileDateFormat);
                writer.write(TextFormat.clean(message));
                writer.write("\r\n");
                CommandReader.getInstance().stashLine();
                System.out.println(colorize(FastAppender.get(TextFormat.AQUA, consoleDateFormat, TextFormat.RESET, message, TextFormat.RESET)));
                CommandReader.getInstance().unstashLine();
            }
        }
        writer.flush();
        writer.close();
    } catch (Exception e) {
        this.logException(e);
    }
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:34,代碼來源:MainLogger.java

示例9: writeResource

import java.io.Writer; //導入方法依賴的package包/類
/**
 * Write <query>.sql to resources folder
 *
 * @param queryDesc information on query
 */
private void writeResource(QueryDesc queryDesc) {
    Filer filer = processingEnv.getFiler();
    try {
        FileObject o = filer.createResource(StandardLocation.CLASS_OUTPUT,
                queryDesc.getPackageName() + ".sql", queryDesc.getMethodNameFirstUpper() + ".sql");
        Writer w = o.openWriter();
        w.append(queryDesc.getQuery());
        w.flush();
        w.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:nds842,項目名稱:sql-first-mapper,代碼行數:19,代碼來源:DaoWriter.java

示例10: process

import java.io.Writer; //導入方法依賴的package包/類
public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
    for (Entry<TypeElement, ViewInjector> entry : findAndParseTargets(env).entrySet()) {
        TypeElement typeElement = (TypeElement) entry.getKey();
        ViewInjector viewInjector = (ViewInjector) entry.getValue();
        try {
            Writer writer = this.filer.createSourceFile(viewInjector.getFqcn(), new Element[]{typeElement}).openWriter();
            writer.write(viewInjector.brewJava());
            writer.flush();
            writer.close();
        } catch (IOException e) {
            error(typeElement, "Unable to write injector for type %s: %s", typeElement, e.getMessage());
        }
    }
    return true;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:ButterKnifeProcessor.java

示例11: writeReport

import java.io.Writer; //導入方法依賴的package包/類
/**
 * Write all execution related to given subscription, from the oldest to the
 * newest.
 */
private void writeReport(final Subscription subscription, final OutputStream output) throws IOException {
	final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
	final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
	writer.write("dateHMS;timestamp;operation;subscription;project;projectKey;projectName;node;trigger;succeed");
	for (final VmExecution execution : vmExecutionRepository.findAllBy("subscription.id", subscription.getId())) {
		writer.write('\n');
		writer.write(df.format(execution.getDate()));
		writer.write(';');
		writer.write(String.valueOf(execution.getDate().getTime()));
		writer.write(';');
		writer.write(execution.getOperation().name());
		writer.write(';');
		writer.write(String.valueOf(subscription.getId()));
		writer.write(';');
		writer.write(String.valueOf(subscription.getProject().getId()));
		writer.write(';');
		writer.write(subscription.getProject().getPkey());
		writer.write(';');
		writer.write(subscription.getProject().getName().replaceAll("\"", "'"));
		writer.write(';');
		writer.write(subscription.getNode().getId());
		writer.write(';');
		writer.write(execution.getTrigger());
		writer.write(';');
		writer.write(String.valueOf(execution.isSucceed()));
	}

	// Ensure buffer is flushed
	writer.flush();
}
 
開發者ID:ligoj,項目名稱:plugin-vm,代碼行數:35,代碼來源:VmResource.java

示例12: writeAssignments

import java.io.Writer; //導入方法依賴的package包/類
private void writeAssignments(Map<String, Integer> assignments, Writer output)
    throws IOException{
  for (Entry<String, Integer> entry : assignments.entrySet()) {
    output.write("    ");
    PackageDistribution.formatEntry(entry, output);
    output.write("\n");
  }
  output.flush();
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:10,代碼來源:VirtualFile.java

示例13: write

import java.io.Writer; //導入方法依賴的package包/類
public static void write(Reader input, OutputStream output, String encoding) throws IOException {
    Writer out = new OutputStreamWriter(output, encoding);
    write(input, out);
    out.flush();
}
 
開發者ID:CodingCodersCode,項目名稱:EvolvingNetLib,代碼行數:6,代碼來源:CCIOUtils.java

示例14: write

import java.io.Writer; //導入方法依賴的package包/類
public static void write(Reader input, OutputStream output) throws IOException {
    Writer out = new OutputStreamWriter(output);
    write(input, out);
    out.flush();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:IOUtils.java

示例15: testRequestBodySwallowing

import java.io.Writer; //導入方法依賴的package包/類
@Test
public void testRequestBodySwallowing() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    SempahoreServlet servlet = new SempahoreServlet();
    Wrapper w = Tomcat.addServlet(ctx, "Test", servlet);
    w.setAsyncSupported(true);
    ctx.addServletMapping("/test", "Test");

    tomcat.start();

    // Hand-craft the client so we have complete control over the timing
    SocketAddress addr = new InetSocketAddress("localhost", getPort());
    Socket socket = new Socket();
    socket.setSoTimeout(300000);
    socket.connect(addr,300000);
    OutputStream os = socket.getOutputStream();
    Writer writer = new OutputStreamWriter(os, "ISO-8859-1");
    InputStream is = socket.getInputStream();
    Reader r = new InputStreamReader(is, "ISO-8859-1");
    BufferedReader reader = new BufferedReader(r);

    // Write the headers
    writer.write("POST /test HTTP/1.1\r\n");
    writer.write("Host: localhost:8080\r\n");
    writer.write("Transfer-Encoding: chunked\r\n");
    writer.write("\r\n");
    writer.flush();

    validateResponse(reader);

    // Write the request body
    writer.write("2\r\n");
    writer.write("AB\r\n");
    writer.write("0\r\n");
    writer.write("\r\n");
    writer.flush();

    // Write the 2nd request
    writer.write("POST /test HTTP/1.1\r\n");
    writer.write("Host: localhost:8080\r\n");
    writer.write("Transfer-Encoding: chunked\r\n");
    writer.write("\r\n");
    writer.flush();

    // Read the 2nd response
    validateResponse(reader);

    // Write the 2nd request body
    writer.write("2\r\n");
    writer.write("AB\r\n");
    writer.write("0\r\n");
    writer.write("\r\n");
    writer.flush();

    // Done
    socket.close();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:62,代碼來源:TestAbstractHttp11Processor.java


注:本文中的java.io.Writer.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。