当前位置: 首页>>代码示例>>Java>>正文


Java Writer.write方法代码示例

本文整理汇总了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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestFixedLengthInputFormat.java

示例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() + ")");
  }
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:22,代码来源:MarkdownTextWriter.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:Streams.java

示例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");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:TestServer.java

示例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;
}
 
开发者ID:hungki,项目名称:tbschedule-wed,代码行数:36,代码来源:ScheduleStrategyDataManager4ZK.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:EditableManifest.java

示例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();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:TestUserDefinedCounters.java

示例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");
}
 
开发者ID:datathings,项目名称:greycat-idea-plugin,代码行数:9,代码来源:PrettyPrinter.java

示例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);
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:13,代码来源:StreamUtil.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: render

import java.io.Writer; //导入方法依赖的package包/类
public void render(String templateFile, Map<String, Object> bindings, Writer out)
        throws IOException {
    out.write(render(templateFile, bindings));
}
 
开发者ID:dwdyoung,项目名称:AndroidWeb,代码行数:5,代码来源:Processor.java

示例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;
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:48,代码来源:IlluminatiProcessor.java

示例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;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:59,代码来源:JSONObject.java

示例14: println

import java.io.Writer; //导入方法依赖的package包/类
protected void println(Writer out, String text) throws IOException {
    out.write(text);
    out.write(lineSep);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:JNIWriter.java

示例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;
}
 
开发者ID:cbedu2,项目名称:CPG,代码行数:59,代码来源:JSONObject.java


注:本文中的java.io.Writer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。