當前位置: 首頁>>代碼示例>>Java>>正文


Java Writer類代碼示例

本文整理匯總了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;
}
 
開發者ID:malikalamgirian,項目名稱:PDF2RDF,代碼行數:27,代碼來源:TitleExtractor.java

示例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
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:JNIWriter.java

示例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);
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:25,代碼來源:AttributeChild.java

示例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);
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:17,代碼來源:UserList.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:XMLKit.java

示例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());
}
 
開發者ID:hungki,項目名稱:tbschedule-wed,代碼行數:31,代碼來源:ScheduleStrategyDataManager4ZK.java

示例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());
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:20,代碼來源:CoreFiltersTest.java

示例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());

}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:22,代碼來源:LogicTest.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:22,代碼來源:XMLTransferManifestWriter.java

示例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);
    }
}
 
開發者ID:CvvT,項目名稱:andbg,代碼行數:21,代碼來源:DexAnnotator.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:CustomMustacheFactory.java

示例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
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:27,代碼來源:VoltTableUtil.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:CompilationUnitTest.java

示例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);
        }
    }

}
 
開發者ID:RETIT,項目名稱:continuous-performance-evaluation,代碼行數:26,代碼來源:RealtimeCargoTrackingService.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:SerialDataConvertor.java


注:本文中的java.io.Writer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。