java.io.FileWriter.flush()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中java.io.FileWriter.flush()方法的一些代码示例,展示了FileWriter.flush()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileWriter.flush()方法的具体详情如下:
包路径:java.io.FileWriter
类名称:FileWriter
方法名:flush

FileWriter.flush介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public void release() throws Exception {
    writer.flush();
    writer.close();
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: alibaba/canal

/**
 * 覆盖本地 canal.properties
 *
 * @param content 远程配置内容文本
 */
private void overrideLocalCanalConfig(String content) {
  try (FileWriter writer = new FileWriter(getConfPath() + "canal.properties")) {
    writer.write(content);
    writer.flush();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: real-logic/agrona

public static Collection<File> persist(final Map<String, CharSequence> sources) throws IOException
{
  final Collection<File> files = new ArrayList<>(sources.size());
  for (final Map.Entry<String, CharSequence> entry : sources.entrySet())
  {
    final String fqClassName = entry.getKey();
    String className = fqClassName;
    Path path = Paths.get(TEMP_DIR_NAME);
    final int indexOfLastDot = fqClassName.lastIndexOf('.');
    if (indexOfLastDot != -1)
    {
      className = fqClassName.substring(indexOfLastDot + 1);
      path = Paths.get(
        TEMP_DIR_NAME + fqClassName.substring(0, indexOfLastDot).replace('.', File.separatorChar));
      Files.createDirectories(path);
    }
    final File file = new File(path.toString(), className + ".java");
    files.add(file);
    try (FileWriter out = new FileWriter(file))
    {
      out.append(entry.getValue());
      out.flush();
    }
  }
  return files;
}

代码示例来源:origin: cmusphinx/sphinx4

/**
 * Writes the transcript file.
 *
 * @param fileName  the name of the decoded file
 * @param reference the reference text
 */
private void writeTranscript(String fileName, String reference) {
  try {
    File file = new File(fileName);
    float start = getSeconds(totalBytes);
    totalBytes += file.length();
    float end = getSeconds(totalBytes);
    transcript.write(context + " 1 " + fileName + ' ' + start +
      ' ' + end + "  " + reference + '\n');
    transcript.flush();
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
}

代码示例来源:origin: orhanobut/logger

@SuppressWarnings("checkstyle:emptyblock")
@Override public void handleMessage(@NonNull Message msg) {
 String content = (String) msg.obj;
 FileWriter fileWriter = null;
 File logFile = getLogFile(folder, "logs");
 try {
  fileWriter = new FileWriter(logFile, true);
  writeLog(fileWriter, content);
  fileWriter.flush();
  fileWriter.close();
 } catch (IOException e) {
  if (fileWriter != null) {
   try {
    fileWriter.flush();
    fileWriter.close();
   } catch (IOException e1) { /* fail silently */ }
  }
 }
}

代码示例来源:origin: graphhopper/graphhopper

private void storeProperties(String graphLocation, String propLocation) {
  logger.info("storing measurement properties in " + propLocation);
  try (FileWriter fileWriter = new FileWriter(propLocation)) {
    String comment = "measurement finish, " + new Date().toString() + ", " + Constants.BUILD_DATE;
    fileWriter.append("#" + comment + "\n");
    for (Entry<String, String> e : properties.entrySet()) {
      fileWriter.append(e.getKey());
      fileWriter.append("=");
      fileWriter.append(e.getValue());
      fileWriter.append("\n");
    }
    fileWriter.flush();
  } catch (IOException e) {
    logger.error("Problem while storing properties " + graphLocation + ", " + propLocation, e);
  }
}

代码示例来源:origin: cmusphinx/sphinx4

/** Writes silence to the transcript file. */
private void writeSilenceToTranscript() {
  try {
    float start = getSeconds(totalBytes);
    totalBytes += silenceFileLength;
    float end = getSeconds(totalBytes);
    transcript.write(context + " 1 " + GAP_LABEL + ' ' +
        start + ' ' + end + " \n");
    transcript.flush();
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: apache/flink

public static File writeYarnSiteConfigXML(Configuration yarnConf) throws IOException {
  tmp.create();
  File yarnSiteXML = new File(tmp.newFolder().getAbsolutePath() + "/yarn-site.xml");
  try (FileWriter writer = new FileWriter(yarnSiteXML)) {
    yarnConf.writeXml(writer);
    writer.flush();
  }
  return yarnSiteXML;
}

代码示例来源:origin: alibaba/canal

/**
 * 覆盖本地application.yml文件
 *
 * @param content 文件内容
 */
private void overrideLocalCanalConfig(String content) {
  try (FileWriter writer = new FileWriter(getConfPath() + "application.yml")) {
    writer.write(content);
    writer.flush();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void get( String arg0, String arg1 ) throws IOException, FTPException {
 FileWriter fw = null;
 try {
  Random r = new Random();
  fw = new FileWriter( arg0 );
  for ( int i = 0; i < 100; i++ ) {
   fw.append( (char) ( r.nextInt( 83 ) + 32 ) );
  }
  fw.flush();
  fw.close();
 } finally {
  if ( fw != null ) {
   fw.close();
  }
 }
}

代码示例来源:origin: commons-io/commons-io

@Test public void testCopy_ByteArray_Writer() throws Exception {
  final File destination = TestUtils.newFile(getTestDirectory(), "copy7.txt");
  byte[] in;
  try (FileInputStream fin = new FileInputStream(m_testFile)) {
    // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
    in = IOUtils.toByteArray(fin);
  }
  try (FileWriter fout = new FileWriter(destination)) {
    CopyUtils.copy(in, fout);
    fout.flush();
    TestUtils.checkFile(destination, m_testFile);
    TestUtils.checkWrite(fout);
  }
  TestUtils.deleteFile(destination);
}

代码示例来源:origin: apache/flink

private void createDashboardConfigFile() throws IOException {
  try (FileWriter fw = createOrGetFile(webDir, "config")) {
    fw.write(createConfigJson(DashboardConfiguration.from(webRefreshIntervalMillis, ZonedDateTime.now())));
    fw.flush();
  } catch (IOException ioe) {
    LOG.error("Failed to write config file.");
    throw ioe;
  }
}

代码示例来源:origin: uber-common/jvm-profiler

@Override
public synchronized void close() {
  closed = true;
  
  List<FileWriter> copy = new ArrayList<>(fileWriters.values());
  for (FileWriter entry : copy) {
    try {
      entry.flush();
      entry.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: Netflix/Priam

@Override
protected void downloadFileImpl(Path remotePath, Path localPath) throws BackupRestoreException {
  AbstractBackupPath path = pathProvider.get();
  path.parseRemote(remotePath.toString());
  if (path.getType() == AbstractBackupPath.BackupFileType.META) {
    // List all files and generate the file
    try (FileWriter fr = new FileWriter(localPath.toFile())) {
      JSONArray jsonObj = new JSONArray();
      for (AbstractBackupPath filePath : flist) {
        if (filePath.type == AbstractBackupPath.BackupFileType.SNAP
            && filePath.time.equals(path.time)) {
          jsonObj.add(filePath.getRemotePath());
        }
      }
      fr.write(jsonObj.toJSONString());
      fr.flush();
    } catch (IOException io) {
      throw new BackupRestoreException(io.getMessage(), io);
    }
  }
  downloadedFiles.add(remotePath.toString());
}

代码示例来源:origin: apache/storm

FileWriter fw = new FileWriter(temp);
yaml.dump(confMap, fw);
fw.flush();
fw.close();

代码示例来源:origin: commons-io/commons-io

@Test public void testCopy_String_Writer() throws Exception {
  final File destination = TestUtils.newFile(getTestDirectory(), "copy6.txt");
  String str;
  try (FileReader fin = new FileReader(m_testFile)) {
    // Create our String. Rely on testReaderToString() to make sure this is valid.
    str = IOUtils.toString(fin);
  }
  try (FileWriter fout = new FileWriter(destination)) {
    CopyUtils.copy(str, fout);
    fout.flush();
    TestUtils.checkFile(destination, m_testFile);
    TestUtils.checkWrite(fout);
  }
  TestUtils.deleteFile(destination);
}

代码示例来源:origin: scouter-project/scouter

public static void processDump(File stackFile, FileWriter stackWriter, FileWriter indexWriter, String [] filters, boolean headerExists) throws Throwable{
  if(stackWriter == null){
    return;
  }
  
  List<String> dumpList = threadDump();
  if(dumpList == null || dumpList.size() == 0){
    return;
  }
  
  String stack = filter(dumpList, filters, headerExists);
  if(stack == null || stack.length() == 0){
    return;
  }
  
  TraceContext.getInstance().lastStack = stack;
  indexWriter.write(new StringBuilder(50).append(System.currentTimeMillis()).append(' ').append(stackFile.length()).append(System.getProperty("line.separator")).toString());
  indexWriter.flush();
  stackWriter.write(stack);
  stackWriter.flush();
}

相关文章