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

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

本文整理了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

  1. /**
  2. * Copies an {@link InputStream} to a File.
  3. * @param in the input stream.
  4. * @param outputFile the output {@link File}.
  5. * @throws OkapiIOException if an error occurs.
  6. */
  7. public static void copy(InputStream in, File outputFile) {
  8. try {
  9. if (!outputFile.exists()) {
  10. Util.createDirectories(outputFile.getAbsolutePath());
  11. outputFile.createNewFile();
  12. }
  13. Files.copy(in, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
  14. } catch (IOException e) {
  15. throw new OkapiIOException(e);
  16. }
  17. }

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

  1. /**
  2. * Copies a file from one location to another.
  3. * @param fromPath the path of the file to copy.
  4. * @param toPath the path of the copy to make.
  5. * @param move true to move the file, false to copy it.
  6. * @throws OkapiIOException if an error occurs.
  7. */
  8. public static void copy(String fromPath, String toPath, boolean move)
  9. {
  10. try {
  11. Util.createDirectories(toPath);
  12. Files.copy(Paths.get(fromPath), Paths.get(toPath), StandardCopyOption.REPLACE_EXISTING);
  13. }
  14. catch ( IOException e ) {
  15. throw new OkapiIOException(e);
  16. }
  17. }

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

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

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

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

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

  1. @Override
  2. protected void processEndBatch () {
  3. // Force creation of needed sub-directories even if empty
  4. Util.createDirectories(manifest.getPackageRoot()+"omegat/");
  5. Util.createDirectories(manifest.getPackageRoot()+"glossary/");
  6. Util.createDirectories(manifest.getTempTargetDirectory());
  7. Util.createDirectories(manifest.getTempTmDirectory());
  8. // Write the OmegaT project file
  9. createOmegaTProject();
  10. // Call base class method
  11. super.processEndBatch();
  12. }

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

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

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

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

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

  1. /**
  2. * Generates the report file with the results.
  3. */
  4. private void generateReport () {
  5. // Output the report
  6. PrintWriter writer = null;
  7. try {
  8. String finalPath = Util.fillRootDirectoryVariable(params.getOutputPath(), rootDir);
  9. finalPath = Util.fillInputRootDirectoryVariable(finalPath, inputRootDir);
  10. Util.createDirectories(finalPath);
  11. writer = new PrintWriter(finalPath, "UTF-8");
  12. for ( Entry<String, Integer> entry : terms.entrySet() ) {
  13. writer.println(String.format("%d\t%s", entry.getValue(), entry.getKey()));
  14. }
  15. }
  16. catch ( IOException e ) {
  17. throw new OkapiException("Error when writing output file.", e);
  18. }
  19. finally {
  20. if ( writer != null ) {
  21. writer.close();
  22. writer = null;
  23. }
  24. }
  25. }

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

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

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

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

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

  1. private void generateReport (String text) {
  2. // Output the report
  3. PrintWriter writer = null;
  4. try {
  5. String finalPath = Util.fillRootDirectoryVariable(params.getLogPath(), rootDir);
  6. finalPath = Util.fillInputRootDirectoryVariable(finalPath, inputRootDir);
  7. Util.createDirectories(finalPath);
  8. writer = new PrintWriter(finalPath, "UTF-8");
  9. writer.println(text);
  10. }
  11. catch ( IOException e ) {
  12. throw new OkapiException("Error when writing output file.", e);
  13. }
  14. finally {
  15. if ( writer != null ) {
  16. writer.close();
  17. writer = null;
  18. }
  19. }
  20. }

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

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

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

  1. @Override
  2. public void prepareForMerge(String dir) {
  3. movedFiles = new HashMap<String, String>();
  4. if (!dir.endsWith(File.separator)) dir = dir + File.separator;
  5. String tmDir = dir + "tm" + File.separator;
  6. Util.createDirectories(tmDir);
  7. String projSave = dir + "omegat" + File.separator + "project_save.tmx";
  8. if (new File(projSave).isFile()) {
  9. String moveTo = uniqueName(tmDir + "project_save.tmx", "-orig");
  10. StreamUtil.copy(projSave, moveTo, true);
  11. movedFiles.put(projSave, moveTo);
  12. }
  13. for (String file : RENAME_FILES) {
  14. if (! new File(dir + file).isFile()) continue;
  15. String moveFrom = dir + file;
  16. String moveTo = uniqueName(dir + file, "-orig");
  17. StreamUtil.copy(moveFrom, moveTo, true);
  18. movedFiles.put(moveFrom, moveTo);
  19. }
  20. File manifest = new File(dir + "manifest.rkm");
  21. if (manifest.isFile()) manifest.delete();
  22. Util.deleteDirectory(dir + "original", false);
  23. Util.deleteDirectory(dir + "source", false);
  24. Util.deleteDirectory(dir + "target", false);
  25. }

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

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

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

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

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

  1. @Override
  2. public Event handleRawDocument (Event event) {
  3. RawDocument rawDoc = null;
  4. try {
  5. rawDoc = (RawDocument)event.getResource();
  6. File outFile = new File(outputURI);
  7. Util.createDirectories(outFile.getAbsolutePath());
  8. StreamUtil.copy(rawDoc.getStream(), outFile);
  9. }
  10. catch ( Throwable e ) {
  11. throw new OkapiIOException("Error writing or copying a RawDocument.", e);
  12. } finally {
  13. if (rawDoc != null) {
  14. rawDoc.close();
  15. }
  16. }
  17. // this steps writes RawDocument then eats the event
  18. return Event.NOOP_EVENT;
  19. }

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

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

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

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

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

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

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

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

相关文章