net.sf.okapi.common.Util.createDirectories()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(152)

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

Util.createDirectories介绍

[英]Creates the directory tree for the give full path (dir+filename)
[中]为给定完整路径(dir+filename)创建目录树

代码示例

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Copies an {@link InputStream} to a File.
 * @param in the input stream.
 * @param outputFile the output {@link File}.
 * @throws OkapiIOException if an error occurs.
 */
public static void copy(InputStream in, File outputFile) {
  try {
    if (!outputFile.exists()) {
      Util.createDirectories(outputFile.getAbsolutePath());
      outputFile.createNewFile();
    }
    Files.copy(in, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
  } catch (IOException e) {
    throw new OkapiIOException(e);
  }
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Copies a file from one location to another.
 * @param fromPath the path of the file to copy.
 * @param toPath the path of the copy to make.
 * @param move true to move the file, false to copy it.
 * @throws OkapiIOException if an error occurs.
 */
public static void copy(String fromPath, String toPath, boolean move)
{
  try {
    Util.createDirectories(toPath);
    Files.copy(Paths.get(fromPath), Paths.get(toPath), StandardCopyOption.REPLACE_EXISTING);
  }
  catch ( IOException e ) {			
    throw new OkapiIOException(e);
  }
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Creates a new XML document on disk.
 * @param path the full path of the document to create. If any directory in the
 * path does not exists yet it will be created automatically. The document is
 * always written in UTF-8 and the type of line-breaks is the one of the
 * platform where the application runs.
 */
public XMLWriter (String path) {
  try {
    Util.createDirectories(path);
    final OutputStreamWriter osw = new OutputStreamWriter(new BufferedOutputStream(
        new FileOutputStream(path)), StandardCharsets.UTF_8);
    writer = new BufferedWriter(osw, defaultCharBufferSize);
  }
  catch ( IOException e ) {
    throw new OkapiIOException(ERRMSG, e);
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-idml

private XMLEventWriter getWriter(String outputPath, Charset charset, XMLOutputFactory outputFactory) {
  Util.createDirectories(outputPath);
  try {
    return outputFactory.createXMLEventWriter(new FileOutputStream(outputPath), charset.name());
  } catch (XMLStreamException | FileNotFoundException e) {
    throw new OkapiIOException(ERROR_CREATING_SUB_DOCUMENT_WRITER, e);
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

@Override
protected void processEndBatch () {
  // Force creation of needed sub-directories even if empty
  Util.createDirectories(manifest.getPackageRoot()+"omegat/");
  Util.createDirectories(manifest.getPackageRoot()+"glossary/");
  Util.createDirectories(manifest.getTempTargetDirectory());
  Util.createDirectories(manifest.getTempTmDirectory());
  // Write the OmegaT project file
  createOmegaTProject();
  
  // Call base class method
  super.processEndBatch();
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-pensieve

private void handleStartDocument (Event event) {
  Util.createDirectories(directory + File.separator);
  // TODO: Move this check at the pensieve package level
  File file = new File(directory + File.separator + "segments.gen");
  // Create a new index only if one does not exists yet
  // If one exists we pass false to append to it
  writer = TmWriterFactory.createFileBasedTmWriter(directory, !file.exists());
  StartDocument sd = (StartDocument) event.getResource();
  srcLoc = sd.getLocale();
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-idml

os = new FileOutputStream(tempZip.getAbsolutePath());
} else {
  Util.createDirectories(outputPath);
  os = new FileOutputStream(outputPath);

代码示例来源:origin: net.sf.okapi.steps/okapi-step-termextraction

/**
 * Generates the report file with the results.
 */
private void generateReport () {
  // Output the report
  PrintWriter writer = null;
  try {
    String finalPath = Util.fillRootDirectoryVariable(params.getOutputPath(), rootDir);
    finalPath = Util.fillInputRootDirectoryVariable(finalPath, inputRootDir);
    Util.createDirectories(finalPath);
    writer = new PrintWriter(finalPath, "UTF-8");
    for ( Entry<String, Integer> entry : terms.entrySet() ) {
      writer.println(String.format("%d\t%s", entry.getValue(), entry.getKey()));
    }
  }
  catch ( IOException e ) {
    throw new OkapiException("Error when writing output file.", e);
  }
  finally {
    if ( writer != null ) {
      writer.close();
      writer = null;
    }
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-icml

Util.createDirectories(outputPath);
xmlOutStream = new FileOutputStream(outputPath);

代码示例来源:origin: net.sf.okapi/okapi-core

Util.createDirectories(workFile.getAbsolutePath());
return workFile;

代码示例来源:origin: net.sf.okapi.steps/okapi-step-searchandreplace

private void generateReport (String text) {
  // Output the report
  PrintWriter writer = null;
  try {
    String finalPath = Util.fillRootDirectoryVariable(params.getLogPath(), rootDir);
    finalPath = Util.fillInputRootDirectoryVariable(finalPath, inputRootDir);
    Util.createDirectories(finalPath);
    writer = new PrintWriter(finalPath, "UTF-8");
    writer.println(text);
  }
  catch ( IOException e ) {
    throw new OkapiException("Error when writing output file.", e);
  }
  finally {
    if ( writer != null ) {
      writer.close();
      writer = null;
    }
  }
}

代码示例来源:origin: net.sf.okapi/okapi-core

os = new FileOutputStream(tempZip.getAbsolutePath());
} else {
  Util.createDirectories(outputPath);
  os = new FileOutputStream(outputPath);

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

@Override
public void prepareForMerge(String dir) {
  movedFiles = new HashMap<String, String>();
  if (!dir.endsWith(File.separator)) dir = dir + File.separator;
  String tmDir = dir + "tm" + File.separator;
  Util.createDirectories(tmDir);
  
  String projSave = dir + "omegat" + File.separator + "project_save.tmx";
  if (new File(projSave).isFile()) {
    String moveTo = uniqueName(tmDir + "project_save.tmx", "-orig");
    StreamUtil.copy(projSave, moveTo, true);
    movedFiles.put(projSave, moveTo);
  }
  for (String file : RENAME_FILES) {
    if (! new File(dir + file).isFile()) continue;
    String moveFrom = dir + file;
    String moveTo = uniqueName(dir + file, "-orig");
    StreamUtil.copy(moveFrom, moveTo, true);
    movedFiles.put(moveFrom, moveTo);
  }
  File manifest = new File(dir + "manifest.rkm");
  if (manifest.isFile()) manifest.delete();
  
  Util.deleteDirectory(dir + "original", false);
  Util.deleteDirectory(dir + "source", false);
  Util.deleteDirectory(dir + "target", false);
}

代码示例来源:origin: net.sf.okapi/okapi-core

try {
  Util.createDirectories(zipPath);
  os = new ZipOutputStream(new FileOutputStream(zipPath));
  for (String name : filenames) {

代码示例来源:origin: net.sf.okapi.tm/okapi-tm-simpletm

deleteFiles(pathNoExt+".*");
else Util.createDirectories(pathNoExt);

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

@Override
public Event handleRawDocument (Event event) {
  RawDocument rawDoc = null;
  try {
    rawDoc = (RawDocument)event.getResource();
    File outFile = new File(outputURI);
    Util.createDirectories(outFile.getAbsolutePath());				
    StreamUtil.copy(rawDoc.getStream(), outFile);                
  }
  catch ( Throwable e ) {
    throw new OkapiIOException("Error writing or copying a RawDocument.", e);
  } finally {
    if (rawDoc != null) {
      rawDoc.close();
    }
  }
  // this steps writes RawDocument then eats the event
  return Event.NOOP_EVENT;
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-repetitionanalysis

@Override
protected Event handleStartDocument(Event event) {
  close();
  // For concurrent pipelines 
  tmDir = String.format("%s~okapi-step-repetitionanalysis-%s/", 
      Util.ensureSeparator(Util.getTempDirectory(), true), 
      UUID.randomUUID().toString());
  Util.createDirectories(tmDir);
  searchExact = params.getFuzzyThreshold() >= 100;
  
  tuCounter = 0;
  groupCounter = 1;
  
  tmWriter = (PensieveWriter) TmWriterFactory.createFileBasedTmWriter(tmDir, true);
  currentTm = new PensieveSeeker(tmWriter.getIndexWriter());
  
  return super.handleStartDocument(event);
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-mosestext

Util.createDirectories(srcOutputPath);
output = new BufferedOutputStream(new FileOutputStream(srcOutputPath));

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

if (outputStream == null) {		        
  outputFile = new File(outputURI);
  Util.createDirectories(outputFile.getAbsolutePath());
  filterWriter.setOutput(outputFile.getAbsolutePath());

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

@Override
protected void processStartDocument (Event event) {
  super.processStartDocument(event);
  
  writer = new XLIFFWriter();
  referents = new LinkedHashMap<String, String>();
  MergingInfo item = manifest.getItem(docId);
  rawDocPath = manifest.getTempSourceDirectory() + item.getRelativeInputPath() + ".xlf";
  // Set the writer's options
  writer.setWithOriginalData(options.getwithOriginalData());
  writer.setUseIndentation(true);
  // Create the writer
  trgLoc = manifest.getTargetLocale();
  Util.createDirectories(rawDocPath); //TODO: This should be done by the writer. To change when it's implemented properly.
  writer.create(new File(rawDocPath), manifest.getSourceLocale().toBCP47(), trgLoc.toBCP47());
  StartXliffData sxd = new StartXliffData(null);
  ITSWriter.addDeclaration(sxd);
  writer.writeStartDocument(sxd, null);
  // Original: use the document name if there is one (null is allowed)
  // For now we don't set ID for the files, the writer will generate them 
  StartFileData sfd = new StartFileData(null);
  sfd.setOriginal(event.getStartDocument().getName());
  writer.setStartFileData(sfd);
}

相关文章