本文整理汇总了Java中java.io.Writer类的典型用法代码示例。如果您正苦于以下问题:Java Writer类的具体用法?Java Writer怎么用?Java Writer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Writer类属于java.io包,在下文中一共展示了Writer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import java.io.Writer; //导入依赖的package包/类
private boolean process() throws IOException {
boolean toReturn = false;
PDFTextStripper stripper = new TitleExtractor();
PDDocument document = null;
try {
document = PDDocument.load(new File(this.getFileNamePathWithExtension()));
//((TitleExtractor) stripper).setFileNamePathWithExtension(this.getFileNamePathWithExtension());
stripper.setSortByPosition(true);
stripper.setStartPage(0);
stripper.setEndPage(1);
Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
stripper.writeText(document, dummy);
setTitle(((TitleExtractor) stripper).getTitle());
toReturn = true;
} finally {
if (document != null) {
document.close();
}
}
return toReturn;
}
示例2: write
import java.io.Writer; //导入依赖的package包/类
/** Emit a class file for a given class.
* @param c The class from which a class file is generated.
*/
public FileObject write(ClassSymbol c)
throws IOException
{
String className = c.flatName().toString();
FileObject outFile
= fileManager.getFileForOutput(StandardLocation.NATIVE_HEADER_OUTPUT,
"", className.replaceAll("[.$]", "_") + ".h", null);
Writer out = outFile.openWriter();
try {
write(out, c);
if (verbose)
log.printVerbose("wrote.file", outFile);
out.close();
out = null;
} finally {
if (out != null) {
// if we are propogating an exception, delete the file
out.close();
outFile.delete();
outFile = null;
}
}
return outFile; // may be null if write failed
}
示例3: encode
import java.io.Writer; //导入依赖的package包/类
/**
* Schrijf dit attribuut.
*
* @param value waarde
* @param writer writer om XML mee te schrijven
* @throws EncodeException bij encodeer foute
*/
@Override
public void encode(final Context context, final T value, final Writer writer) throws EncodeException {
LOGGER.debug("encode(value={})", value);
if (value == null) {
return;
}
try {
writer.append(" ");
writer.append(getName());
writer.append("=\"");
writer.append(converter.encode(context, value));
writer.append("\"");
} catch (final IOException e) {
throw new EncodeException(context.getElementStack(), e);
}
}
示例4: writeChanges
import java.io.Writer; //导入依赖的package包/类
public void writeChanges() throws IOException
{
Collection<V> collection = this.values.values();
String s = this.gson.toJson((Object)collection);
BufferedWriter bufferedwriter = null;
try
{
bufferedwriter = Files.newWriter(this.saveFile, Charsets.UTF_8);
bufferedwriter.write(s);
}
finally
{
IOUtils.closeQuietly((Writer)bufferedwriter);
}
}
示例5: writeCData
import java.io.Writer; //导入依赖的package包/类
public static void writeCData(String val, Writer w) throws IOException {
String begCData = "<![CDATA[";
String endCData = "]]>";
w.write(begCData);
for (int vpos = 0, split;; vpos = split) {
split = val.indexOf(endCData, vpos);
if (split < 0) {
w.write(val, vpos, val.length() - vpos);
w.write(endCData);
return;
}
split += 2; // bisect the "]]>" goo
w.write(val, vpos, split - vpos);
w.write(endCData);
w.write(begCData);
}
}
示例6: importConfig
import java.io.Writer; //导入依赖的package包/类
/**
* 导入配置信息【目前支持baseTaskType和strategy数据】
*
* @param config
* @param writer
* @param isUpdate
* @throws Exception
*/
public void importConfig(String config, Writer writer, boolean isUpdate)
throws Exception {
ConfigNode configNode = gson.fromJson(config, ConfigNode.class);
if (configNode != null) {
String path = configNode.getRootPath() + "/"
+ configNode.getConfigType();
ZKTools.createPath(getZooKeeper(), path, CreateMode.PERSISTENT, zkManager.getAcl());
String y_node = path + "/" + configNode.getName();
if (getZooKeeper().exists(y_node, false) == null) {
writer.append("<font color=\"red\">成功导入新配置信息\n</font>");
getZooKeeper().create(y_node, configNode.getValue().getBytes(),
zkManager.getAcl(), CreateMode.PERSISTENT);
} else if (isUpdate) {
writer.append("<font color=\"red\">该配置信息已经存在,并且强制更新了\n</font>");
getZooKeeper().setData(y_node,
configNode.getValue().getBytes(), -1);
} else {
writer.append("<font color=\"red\">该配置信息已经存在,如果需要更新,请配置强制更新\n</font>");
}
}
writer.append(configNode.toString());
}
示例7: testDate
import java.io.Writer; //导入依赖的package包/类
@Test
public void testDate() throws ParseException, PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false)
.defaultLocale(Locale.ENGLISH).build();
String source = "{{ realDate | date('MM/dd/yyyy') }}{{ realDate | date(format) }}{{ stringDate | date('yyyy/MMMM/d','yyyy-MMMM-d') }}";
PebbleTemplate template = pebble.getTemplate(source);
Map<String, Object> context = new HashMap<>();
DateFormat format = new SimpleDateFormat("yyyy-MMMM-d", Locale.ENGLISH);
Date realDate = format.parse("2012-July-01");
context.put("realDate", realDate);
context.put("stringDate", format.format(realDate));
context.put("format", "yyyy-MMMM-d");
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("07/01/20122012-July-12012/July/1", writer.toString());
}
示例8: testMacroSafeStringConcatenation
import java.io.Writer; //导入依赖的package包/类
/**
* Tests if the macro output SafeString concatenation is working.
*/
@Test
public void testMacroSafeStringConcatenation() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "{% macro macro1() %}Bob{% endmacro %}\n"
+ "{% macro macro2() %}Maria{% endmacro %}\n"
+ "{% macro macro3() %}John{% endmacro %}\n"
+ "{{ (macro1() + macro2() + macro3()) | lower }}";
PebbleTemplate template = pebble.getTemplate(source);
Map<String, Object> context = new HashMap<>();
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("bobmariajohn", writer.toString());
}
示例9: startTransferManifest
import java.io.Writer; //导入依赖的package包/类
/**
* Start the transfer manifest
*/
public void startTransferManifest(Writer writer) throws SAXException
{
format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(3);
format.setEncoding("UTF-8");
this.writer = new XMLWriter(writer, format);
this.writer.startDocument();
this.writer.startPrefixMapping(PREFIX, TransferModel.TRANSFER_MODEL_1_0_URI);
this.writer.startPrefixMapping("cm", NamespaceService.CONTENT_MODEL_1_0_URI);
// Start Transfer Manifest // uri, name, prefix
this.writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
ManifestModel.LOCALNAME_TRANSFER_MAINIFEST, PREFIX + ":"
+ ManifestModel.LOCALNAME_TRANSFER_MAINIFEST, EMPTY_ATTRIBUTES);
}
示例10: writeAnnotations
import java.io.Writer; //导入依赖的package包/类
public void writeAnnotations(Writer out) throws IOException {
List<MapItem> mapItems = dexFile.getMapItems();
// sort the map items based on the order defined by sectionAnnotationOrder
Ordering<MapItem> ordering = Ordering.from(new Comparator<MapItem>() {
@Override public int compare(MapItem o1, MapItem o2) {
return Ints.compare(sectionAnnotationOrder.get(o1.getType()), sectionAnnotationOrder.get(o2.getType()));
}
});
mapItems = ordering.immutableSortedCopy(mapItems);
try {
for (MapItem mapItem: mapItems) {
SectionAnnotator annotator = annotators.get(mapItem.getType());
annotator.annotateSection(this);
}
} finally {
dexFile.writeAnnotations(out, this);
}
}
示例11: run
import java.io.Writer; //导入依赖的package包/类
@Override
public Writer run(Writer writer, List<Object> scopes) {
if (getCodes() != null) {
for (Code code : getCodes()) {
try (StringWriter capture = new StringWriter()) {
code.execute(capture, scopes);
String s = capture.toString();
if (s != null) {
encoder.encode(s, writer);
}
} catch (IOException e) {
throw new MustacheException("Exception while parsing mustache function at line " + tc.line(), e);
}
}
}
return writer;
}
示例12: csv
import java.io.Writer; //导入依赖的package包/类
/**
* Dump out a VoltTable as a CSV to the given writer
* If the header flag is set to true, then the output will include
* the column names in the first row
* @param out
* @param vt
* @param write_header
*/
public static void csv(Writer out, VoltTable vt, boolean header) {
CSVWriter writer = new CSVWriter(out);
if (header) {
String cols[] = new String[vt.getColumnCount()];
for (int i = 0; i < cols.length; i++) {
cols[i] = vt.getColumnName(i);
} // FOR
writer.writeNext(cols);
}
vt.resetRowPosition();
while (vt.advanceRow()) {
String row[] = vt.getRowStringArray();
assert(row != null);
assert(row.length == vt.getColumnCount());
writer.writeNext(row);
} // WHILE
}
示例13: setupJavaTemplates
import java.io.Writer; //导入依赖的package包/类
private void setupJavaTemplates() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"package zoo;\n" +
"\n" +
"public class A {\n" +
"}\n"
);
FileObject emptyJava = FileUtil.createData(FileUtil.getConfigRoot(), "Templates/Classes/Empty.java");
emptyJava.setAttribute("template", Boolean.TRUE);
classJava = FileUtil.createData(FileUtil.getConfigRoot(), "Templates/Classes/Class.java");
classJava.setAttribute("template", Boolean.TRUE);
classJava.setAttribute("verbatim-create-from-template", Boolean.TRUE);
template = "/*\r\ninitial\r\ncomment\r\n*/\r\npackage zoo;\r\npublic class Template {\r\n public Template() {}\r\n}\r\n";
Writer w = new OutputStreamWriter(classJava.getOutputStream(), "UTF-8");
w.write(template);
w.close();
}
示例14: onCargoInspected
import java.io.Writer; //导入依赖的package包/类
public void onCargoInspected(@Observes @CargoInspected Cargo cargo) {
Writer writer = new StringWriter();
try (JsonGenerator generator = Json.createGenerator(writer)) {
generator
.writeStartObject()
.write("trackingId", cargo.getTrackingId().getIdString())
.write("origin", cargo.getOrigin().getName())
.write("destination", cargo.getRouteSpecification().getDestination().getName())
.write("lastKnownLocation", cargo.getDelivery().getLastKnownLocation().getName())
.write("transportStatus", cargo.getDelivery().getTransportStatus().toString())
.writeEnd();
}
String jsonValue = writer.toString();
for (Session session : sessions) {
try {
session.getBasicRemote().sendText(jsonValue);
} catch (IOException ex) {
logger.log(Level.WARNING, "Unable to publish WebSocket message", ex);
}
}
}
示例15: writeDown
import java.io.Writer; //导入依赖的package包/类
/** store the setting object even if was not changed */
private void writeDown() throws IOException {
Object inst = instance.get();
if (inst == null) return ;
ByteArrayOutputStream b = new ByteArrayOutputStream(1024);
Writer w = new OutputStreamWriter(b, "UTF-8"); // NOI18N
try {
isWriting = true;
Convertor conv = getConvertor();
if (conv != null) {
conv.write(w, inst);
} else {
write(w, inst);
}
} finally {
w.close();
isWriting = false;
}
isChanged = false;
buf = b;
file.getFileSystem().runAtomicAction(this);
buf = null;
if (!isChanged) firePropertyChange(PROP_SAVE);
}