当前位置: 首页>>代码示例>>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;未经允许,请勿转载。