本文整理汇总了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());
}
示例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();
}
示例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);
}
}
示例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");
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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