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


Java Writer.close方法代码示例

本文整理汇总了Java中java.io.Writer.close方法的典型用法代码示例。如果您正苦于以下问题:Java Writer.close方法的具体用法?Java Writer.close怎么用?Java Writer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.Writer的用法示例。


在下文中一共展示了Writer.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFiles

import java.io.Writer; //导入方法依赖的package包/类
private static void createFiles(int length, int numFiles, Random random)
  throws IOException {
  Range[] ranges = createRanges(length, numFiles, random);

  for (int i = 0; i < numFiles; i++) {
    Path file = new Path(workDir, "test_" + i + ".txt");
    Writer writer = new OutputStreamWriter(localFs.create(file));
    Range range = ranges[i];
    try {
      for (int j = range.start; j < range.end; j++) {
        writer.write(Integer.toString(j));
        writer.write("\n");
      }
    } finally {
      writer.close();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestCombineTextInputFormat.java

示例2: write

import java.io.Writer; //导入方法依赖的package包/类
public static boolean write() {
	FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
	JsonObject json = new JsonObject();
	for (Map.Entry<String, Setting> entry : settings.entrySet()) {
		json.set(entry.getKey(), entry.getValue().toJson());
	}
	try {
		Writer writer = fileHandle.writer(false);
		json.writeTo(writer, WriterConfig.PRETTY_PRINT);
		writer.close();
	} catch (Exception e) {
		Log.error("Failed to write settings", e);
		fileHandle.delete();
		return false;
	}
	return true;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:18,代码来源:Settings.java

示例3: testCloseFlush

import java.io.Writer; //导入方法依赖的package包/类
public void testCloseFlush() throws IOException {
  SpyAppendable spy = new SpyAppendable();
  Writer writer = new AppendableWriter(spy);

  writer.write("Hello");
  assertFalse(spy.flushed);
  assertFalse(spy.closed);

  writer.flush();
  assertTrue(spy.flushed);
  assertFalse(spy.closed);

  writer.close();
  assertTrue(spy.flushed);
  assertTrue(spy.closed);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:AppendableWriterTest.java

示例4: process

import java.io.Writer; //导入方法依赖的package包/类
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver() || written++ > 0) {
        return false;
    }
    messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
    try {
        Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
        try {
            w.write("package p; public class Generated { public static void m() { } }");
        } finally {
            w.close();
        }
    } catch (IOException x) {
        messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:T7159016.java

示例5: testNoManifest

import java.io.Writer; //导入方法依赖的package包/类
@Test
public void testNoManifest() throws Exception {
  File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
                      TestJarFinder.class.getName() + "-testNoManifest");
  delete(dir);
  dir.mkdirs();
  File propsFile = new File(dir, "props.properties");
  Writer writer = new FileWriter(propsFile);
  new Properties().store(writer, "");
  writer.close();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  JarOutputStream zos = new JarOutputStream(baos);
  JarFinder.jarDir(dir, "", zos);
  JarInputStream jis =
    new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
  Assert.assertNotNull(jis.getManifest());
  jis.close();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TestJarFinder.java

示例6: main

import java.io.Writer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    File src = new File("C.java");
    Writer w = new FileWriter(src);
    try {
        w.write("import static p.Generated.m;\nclass C { {m(); } }\n");
        w.flush();
    } finally {
        w.close();
    }
    JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null)) {
        JavaCompiler.CompilationTask task = jc.getTask(null, fm, null, null, null,
                                                       fm.getJavaFileObjects(src));
        task.setProcessors(Collections.singleton(new Proc()));
        if (!task.call()) {
            throw new Error("Test failed");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:T7159016.java

示例7: 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

示例8: writeNonEffectivePom

import java.io.Writer; //导入方法依赖的package包/类
private void writeNonEffectivePom(final Writer pomWriter) throws IOException {
    try {
        withXmlActions.transform(pomWriter, POM_FILE_ENCODING, new ErroringAction<Writer>() {
            protected void doExecute(Writer writer) throws IOException {
                new MavenXpp3Writer().write(writer, getModel());
            }
        });
    } finally {
        pomWriter.close();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:12,代码来源:DefaultMavenPom.java

示例9: testExistingManifest

import java.io.Writer; //导入方法依赖的package包/类
@Test
public void testExistingManifest() throws Exception {
  File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
                      TestJarFinder.class.getName() + "-testExistingManifest");
  delete(dir);
  dir.mkdirs();

  File metaInfDir = new File(dir, "META-INF");
  metaInfDir.mkdirs();
  File manifestFile = new File(metaInfDir, "MANIFEST.MF");
  Manifest manifest = new Manifest();
  OutputStream os = new FileOutputStream(manifestFile);
  manifest.write(os);
  os.close();

  File propsFile = new File(dir, "props.properties");
  Writer writer = new FileWriter(propsFile);
  new Properties().store(writer, "");
  writer.close();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  JarOutputStream zos = new JarOutputStream(baos);
  JarFinder.jarDir(dir, "", zos);
  JarInputStream jis =
    new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
  Assert.assertNotNull(jis.getManifest());
  jis.close();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:TestJarFinder.java

示例10: _testAuthentication

import java.io.Writer; //导入方法依赖的package包/类
protected void _testAuthentication(Authenticator authenticator, boolean doPost) throws Exception {
  start();
  try {
    URL url = new URL(getBaseURL());
    AuthenticatedURL.Token token = new AuthenticatedURL.Token();
    Assert.assertFalse(token.isSet());
    TestConnectionConfigurator connConf = new TestConnectionConfigurator();
    AuthenticatedURL aUrl = new AuthenticatedURL(authenticator, connConf);
    HttpURLConnection conn = aUrl.openConnection(url, token);
    Assert.assertTrue(connConf.invoked);
    String tokenStr = token.toString();
    if (doPost) {
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
    }
    conn.connect();
    if (doPost) {
      Writer writer = new OutputStreamWriter(conn.getOutputStream());
      writer.write(POST);
      writer.close();
    }
    Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
    if (doPost) {
      BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String echo = reader.readLine();
      Assert.assertEquals(POST, echo);
      Assert.assertNull(reader.readLine());
    }
    aUrl = new AuthenticatedURL();
    conn = aUrl.openConnection(url, token);
    conn.connect();
    Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
    Assert.assertEquals(tokenStr, token.toString());
  } finally {
    stop();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:38,代码来源:AuthenticatorTestCase.java

示例11: writedoc

import java.io.Writer; //导入方法依赖的package包/类
/**
 *  Writes the given element's subtree to the specified file.
 *
 * @param  fname           The output file name
 * @param  ele             The xml Element subtree to write to file
 * @param  doc             The Document
 * @return                 True if content previously existed in the given file and the content is the same
 *      as the new content provided
 * @exception  Hexception  If exception
 */
private boolean writedoc(
		String fname,
		Element ele,
		Document doc)
		 throws Hexception {
	try {
		boolean contentEquals = false;

		String s1 = null;
		File f = new File(fname);
		if (f.exists())
			s1 = Files.readFileToEncoding(f, "UTF-8").toString();

		FileOutputStream fos = new FileOutputStream(f);
		OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
		Writer wtr = new BufferedWriter(osw);
		OutputFormat format = new OutputFormat(doc, "UTF-8", true);
		// Indenting true
		format.setMethod("xml");
		// May not ne necessary to call this
		format.setLineWidth(0);
		// No line wrapping
		XMLSerializer ser = new XMLSerializer(wtr, format);
		ser.serialize(ele);
		fos.close();
		osw.close();
		wtr.close();

		if (s1 != null)
			contentEquals = s1.contentEquals(Files.readFileToEncoding(f, "UTF-8"));

		return contentEquals;
	} catch (IOException ioe) {
		throw new Hexception("cannot write file \"" + fname
				 + "\"  reason: " + ioe);
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:48,代码来源:Harvester.java

示例12: performTestDoNotPerform

import java.io.Writer; //导入方法依赖的package包/类
protected void performTestDoNotPerform(String className, int line, int column) throws Exception {
    prepareTest(className);
    DataObject od = DataObject.find(testSource);
    EditorCookie ec = od.getCookie(EditorCookie.class);
    
    Document doc = ec.openDocument();
    
    List<ErrorDescription> errors = new ErrorHintsProvider().computeErrors(info, doc, Utilities.JAVA_MIME_TYPE);
    List<Fix> fixes = new ArrayList<Fix>();
    
    for (ErrorDescription d : errors) {
        if (getStartLine(d) + 1 == line)
            fixes.addAll(getFixes(d));
    }
    
    fixes = sortFixes(fixes);
    
    File fixesDump = new File(getWorkDir(), getName() + "-hints.out");
    File diff   = new File(getWorkDir(), getName() + "-hints.diff");
    
    Writer hintsWriter = new FileWriter(fixesDump);
    
    for (Fix f : fixes) {
        hintsWriter.write(f.getText());
        hintsWriter.write("\n");
    }
    
    hintsWriter.close();
    
    File hintsGolden = getGoldenFile(getName() + "-hints.pass");
    
    assertFile(fixesDump, hintsGolden, diff);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:HintsTestBase.java

示例13: createFile

import java.io.Writer; //导入方法依赖的package包/类
protected Path createFile(String fileName) throws IOException {
  Path file = new Path(workDir, fileName);
  Writer writer = new OutputStreamWriter(localFs.create(file));
  writer.write("");
  writer.close();
  return localFs.makeQualified(file);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:TestFileInputFormatPathFilter.java

示例14: 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);
    }
}
 
开发者ID:nds842,项目名称:sql-first-mapper,代码行数:19,代码来源:DaoWriter.java

示例15: testExtractPassword

import java.io.Writer; //导入方法依赖的package包/类
@Test
public void testExtractPassword() throws IOException {
  File testDir = new File(System.getProperty("test.build.data", 
                                             "target/test-dir"));
  testDir.mkdirs();
  File secretFile = new File(testDir, "secret.txt");
  Writer writer = new FileWriter(secretFile);
  writer.write("hadoop");
  writer.close();
  
  LdapGroupsMapping mapping = new LdapGroupsMapping();
  Assert.assertEquals("hadoop",
      mapping.extractPassword(secretFile.getPath()));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:TestLdapGroupsMapping.java


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