本文整理汇总了Java中java.io.Writer.write方法的典型用法代码示例。如果您正苦于以下问题:Java Writer.write方法的具体用法?Java Writer.write怎么用?Java Writer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.Writer
的用法示例。
在下文中一共展示了Writer.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFile
import java.io.Writer; //导入方法依赖的package包/类
private ArrayList<String> createFile(Path targetFile, CompressionCodec codec,
int recordLen,
int numRecords) throws IOException {
ArrayList<String> recordList = new ArrayList<String>(numRecords);
OutputStream ostream = localFs.create(targetFile);
if (codec != null) {
ostream = codec.createOutputStream(ostream);
}
Writer writer = new OutputStreamWriter(ostream);
try {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < numRecords; i++) {
for (int j = 0; j < recordLen; j++) {
sb.append(chars[charRand.nextInt(chars.length)]);
}
String recordData = sb.toString();
recordList.add(recordData);
writer.write(recordData);
sb.setLength(0);
}
} finally {
writer.close();
}
return recordList;
}
示例2: endEntity
import java.io.Writer; //导入方法依赖的package包/类
private void endEntity(Entry<Attribute, Object> entry, Writer writer) throws IOException {
if (entry == null) {
return;
}
Attribute entity = entry.getKey();
if (entity == TextEntity.BOLD) {
writer.write('*');
} else if (entity == TextEntity.ITALIC) {
writer.write('_');
} else if (entity == TextEntity.CODE) {
writer.write('`');
} else if (entity == TextEntity.CODE_BLOCK) {
writer.write("```");
} else if (entity == TextEntity.LINK) {
writer.write("](" + entry.getValue() + ')');
} else if (entity == TextEntity.TEXT_MENTION) {
User user = (User) entry.getValue();
writer.write("](" + TextEntity.TEXT_MENTION_LINK + user.getId() + ")");
}
}
示例3: copy
import java.io.Writer; //导入方法依赖的package包/类
/**
* Copy the contents of the given Reader to the given Writer.
* Closes both when done.
*
* @param in the Reader to copy from
* @param out the Writer to copy to
* @return the number of characters copied
* @throws IOException in case of I/O errors
*/
public static int copy(Reader in, Writer out) throws IOException {
Objects.requireNonNull(in, "No Reader specified");
Objects.requireNonNull(out, "No Writer specified");
boolean success = false;
try {
int byteCount = 0;
char[] buffer = new char[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
byteCount += bytesRead;
}
out.flush();
success = true;
return byteCount;
} finally {
if (success) {
IOUtils.close(in, out);
} else {
IOUtils.closeWhileHandlingException(in, out);
}
}
}
示例4: loadingSiteConfig
import java.io.Writer; //导入方法依赖的package包/类
@Test
@TestDir
public void loadingSiteConfig() throws Exception {
String dir = TestDirHelper.getTestDir().getAbsolutePath();
File configFile = new File(dir, "testserver-site.xml");
Writer w = new FileWriter(configFile);
w.write("<configuration><property><name>testserver.a</name><value>site</value></property></configuration>");
w.close();
Server server = new Server("testserver", dir, dir, dir, dir);
server.init();
assertEquals(server.getConfig().get("testserver.a"), "site");
}
示例5: exportConfig
import java.io.Writer; //导入方法依赖的package包/类
/**
* 输出配置信息【目前备份baseTaskType和strategy数据】
*
* @param rootPath
* @param writer
* @throws Exception
*/
public StringBuffer exportConfig(String rootPath, Writer writer)
throws Exception {
StringBuffer buffer = new StringBuffer();
for (String type : new String[] { "baseTaskType", "strategy" }) {
if (type.equals("baseTaskType")) {
writer.write("<h2>基本任务配置列表:</h2>\n");
} else {
writer.write("<h2>基本策略配置列表:</h2>\n");
}
String bTTypePath = rootPath + "/" + type;
List<String> fNodeList = getZooKeeper().getChildren(bTTypePath,
false);
for (int i = 0; i < fNodeList.size(); i++) {
String fNode = fNodeList.get(i);
ConfigNode configNode = new ConfigNode(rootPath, type, fNode);
configNode.setValue(new String(this.getZooKeeper().getData(bTTypePath + "/" + fNode,false,null)));
buffer.append(gson.toJson(configNode));
buffer.append("\n");
writer.write(configNode.toString());
}
writer.write("\n\n");
}
if (buffer.length() > 0) {
String str = buffer.toString();
return new StringBuffer(str.substring(0, str.length() - 1));
}
return buffer;
}
示例6: write
import java.io.Writer; //导入方法依赖的package包/类
public void write(Writer w) throws IOException {
// translating all newlines to correct format,
// see SingleModulePropertiesTest#testThatManifestFormattingIsNotMessedUp_61248
String output = NEWLINE.matcher(text).replaceAll(RET);
w.write(output);
newline(w);
}
示例7: cleanAndCreateInput
import java.io.Writer; //导入方法依赖的package包/类
private void cleanAndCreateInput(FileSystem fs) throws IOException {
fs.delete(INPUT_DIR, true);
fs.delete(OUTPUT_DIR, true);
OutputStream os = fs.create(INPUT_FILE);
Writer wr = new OutputStreamWriter(os);
wr.write("hello1\n");
wr.write("hello2\n");
wr.write("hello3\n");
wr.write("hello4\n");
wr.close();
}
示例8: printEnum
import java.io.Writer; //导入方法依赖的package包/类
private void printEnum(Writer sw, EEnum en) throws IOException {
sw.write("\n");
sw.write("enum " + fqn(en) + " {\n");
for (EEnumLiteral literal : en.getELiterals()) {
sw.append(" " + literal.getLiteral() + "\n");
}
sw.write("}\n");
}
示例9: io
import java.io.Writer; //导入方法依赖的package包/类
public static void io(Reader in, Writer out, int bufferSize) throws IOException {
if (bufferSize == -1) {
bufferSize = DEFAULT_BUFFER_SIZE >> 1;
}
char[] buffer = new char[bufferSize];
int amount;
while ((amount = in.read(buffer)) >= 0) {
out.write(buffer, 0, amount);
}
}
示例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: render
import java.io.Writer; //导入方法依赖的package包/类
public void render(String templateFile, Map<String, Object> bindings, Writer out)
throws IOException {
out.write(render(templateFile, bindings));
}
示例12: process
import java.io.Writer; //导入方法依赖的package包/类
@Override public boolean process(Set<? extends TypeElement> typeElements, RoundEnvironment env) {
this.messager.printMessage(Kind.WARNING, "start illuminati compile");
outerloop:
for (TypeElement typeElement : typeElements) {
for (Element element : env.getElementsAnnotatedWith(typeElement)) {
Illuminati illuminati = element.getAnnotation(Illuminati.class);
if (illuminati != null) {
if (element.getKind() != ElementKind.CLASS && element.getKind() != ElementKind.METHOD) {
this.messager.printMessage(Kind.ERROR, "The class %s is not class or method."+ element.getSimpleName());
break outerloop;
}
final PackageElement pkg = processingEnv.getElementUtils().getPackageOf(element);
if (pkg == null) {
// Exception
this.messager.printMessage(Kind.ERROR, "Sorry, basePackage is wrong in properties read process.");
break outerloop;
}
if(this.setGeneratedIlluminatiTemplate(pkg.toString())) {
try {
final JavaFileObject javaFile = this.filer.createSourceFile("IlluminatiPointcutGenerated");
final Writer writer = javaFile.openWriter();
if (writer != null) {
writer.write(this.generatedIlluminatiTemplate);
writer.close();
this.messager.printMessage(Kind.NOTE, "generate source code!!");
} else {
this.messager.printMessage(Kind.ERROR, "Sorry, something is wrong in writer 'IlluminatiPointcutGenerated.java' process.");
}
// IlluminatiPointcutGenerated must exists only one on classloader.
break outerloop;
} catch (IOException e) {
this.messager.printMessage(Kind.ERROR, "Sorry, something is wrong in generated 'IlluminatiPointcutGenerated.java' process.");
break outerloop;
}
}
}
}
}
return true;
}
示例13: quote
import java.io.Writer; //导入方法依赖的package包/类
public static Writer quote(String string, Writer w) throws IOException {
if (string == null || string.length() == 0) {
w.write("\"\"");
return w;
}
char b;
char c = 0;
String hhhh;
int i;
int len = string.length();
w.write('"');
for (i = 0; i < len; i += 1) {
b = c;
c = string.charAt(i);
switch (c) {
case '\\':
case '"':
w.write('\\');
w.write(c);
break;
case '/':
if (b == '<') {
w.write('\\');
}
w.write(c);
break;
case '\b':
w.write("\\b");
break;
case '\t':
w.write("\\t");
break;
case '\n':
w.write("\\n");
break;
case '\f':
w.write("\\f");
break;
case '\r':
w.write("\\r");
break;
default:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|| (c >= '\u2000' && c < '\u2100')) {
w.write("\\u");
hhhh = Integer.toHexString(c);
w.write("0000", 0, 4 - hhhh.length());
w.write(hhhh);
} else {
w.write(c);
}
}
}
w.write('"');
return w;
}
示例14: println
import java.io.Writer; //导入方法依赖的package包/类
protected void println(Writer out, String text) throws IOException {
out.write(text);
out.write(lineSep);
}
示例15: quote
import java.io.Writer; //导入方法依赖的package包/类
public static Writer quote(String string, Writer w) throws IOException {
if (string == null || string.length() == 0) {
w.write("\"\"");
return w;
}
char b;
char c = 0;
String hhhh;
int i;
int len = string.length();
w.write('"');
for (i = 0; i < len; i += 1) {
b = c;
c = string.charAt(i);
switch (c) {
case '\\':
case '"':
w.write('\\');
w.write(c);
break;
case '/':
if (b == '<') {
w.write('\\');
}
w.write(c);
break;
case '\b':
w.write("\\b");
break;
case '\t':
w.write("\\t");
break;
case '\n':
w.write("\\n");
break;
case '\f':
w.write("\\f");
break;
case '\r':
w.write("\\r");
break;
default:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|| (c >= '\u2000' && c < '\u2100')) {
w.write("\\u");
hhhh = Integer.toHexString(c);
w.write("0000", 0, 4 - hhhh.length());
w.write(hhhh);
} else {
w.write(c);
}
}
}
w.write('"');
return w;
}