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


Java Files类代码示例

本文整理汇总了Java中gate.util.Files的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initialize

import gate.util.Files; //导入依赖的package包/类
private void initialize() throws FileNotFoundException, IOException, MalformedURLException, URISyntaxException, Exception {
    
    pdfPanel.addMouseListener(actionListener);
    pdfPanel.addMouseMotionListener(actionListener);
    pdfPanel.addKeyListener(actionListener);
    pdfPanel.setComponentPopupMenu(menu);
    
    byte[] pdfBytes = null;
    if(DataURL.isDataURL(source)) {
        pdfBytes = new DataURL(source).getData();
    }
    else {
        URL sourceURL = new URL(source);
        if("file".equalsIgnoreCase(sourceURL.getProtocol())) {
            pdfBytes = Files.getByteArray(new File(sourceURL.toURI()));
        }
        else {
            pdfBytes = IObox.fetchUrl(sourceURL);
        }
    }
    
    if(pdfBytes != null) {
        pdfFile = new PDFFile(ByteBuffer.wrap(pdfBytes));
        if(pdfFile != null) {
            pageCount = pdfFile.getNumPages();
            if(pageCount > 0) {
                setPageText.invoke(1, pageCount);
                pdfPanel.changePage(pdfFile.getPage(0));
            }
            else {
                throw new Exception("PDF has no pages at all. Can't view.");
            }          
        }
    }
    else {
        throw new Exception("Can't read data out of locator resource.");
    }
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:39,代码来源:ApplicationPDF.java

示例2: runTagger

import gate.util.Files; //导入依赖的package包/类
/**
 * This method is responsible for executing the external tagger. If a
 * problem is going to occur this is likely to be the place!
 * 
 * @param cmdline the command line we want to execute
 * @return an InputStream from which the output of the tagger can be
 *         read
 * @throws ExecutionException if an error occurs executing the tagger
 */
protected InputStream runTagger(String[] cmdline) throws ExecutionException {
  
  ByteArrayOutputStream baout = new ByteArrayOutputStream();
  
  try {
    int returnCode;
    if(taggerDir == null) {
      returnCode = processManager.runProcess(cmdline, baout, (debug ? System.err : null));
    }
    else {
      returnCode = processManager.runProcess(cmdline, Files.fileFromURL(taggerDir), baout, (debug ? System.err : null));
    }
    
    if (debug) System.err.println("Return Code From Tagger: "+returnCode);
    
    return new ByteArrayInputStream(baout.toByteArray());
  }
  catch(Exception e) {
    throw new ExecutionException(e);
  }
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:31,代码来源:GenericTagger.java

示例3: PrivateRepositoryFeed

import gate.util.Files; //导入依赖的package包/类
public PrivateRepositoryFeed(URL configFileUrl, String query, int settingsHash, Options opt) {
	this.configFile = Files.fileFromURL(configFileUrl);		
	this.query = query;
	this.settingsHash = settingsHash;
	dictionaryPath = configFile.getParentFile().getAbsoluteFile();
	this.username = opt.getMap().get("username");
	this.password = opt.getMap().get("password");
	
	if (!verifyHash(dictionaryPath, settingsHash)) {
		boolean deleteSuccesful = new File(dictionaryPath, "kim.trusted.entities.cache").delete();
		if (deleteSuccesful) {
			log.info("Cache is going to be refreshed due to a configuration change.");
		}
		else {
			log.warn("Cache needed to be refreshed due to a configuration change, but the system denied deleting it.");
		}
	}		
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:19,代码来源:PrivateRepositoryFeed.java

示例4: createSesameFeed

import gate.util.Files; //导入依赖的package包/类
private QueryResultListener.Feed createSesameFeed(File dictionaryPath, Options opt) {
	File queryFile = new File(dictionaryPath, "query.txt").getAbsoluteFile();
	try {
		URL configFileUrl = new File(dictionaryPath, "config.ttl").getAbsoluteFile().toURI().toURL();
		if (!Files.fileFromURL(configFileUrl).isFile()) {
		  log.info("No config.ttl file in " + dictionaryPath);
		  return null;
		}
		if (!queryFile.exists()) {
		  log.info("No query.txt file in " + dictionaryPath);
		  return null;
		}
		String queryString = FileUtils.readFileToString(queryFile);
		log.info("Query loaded from " + queryFile);
		int settingsHash = new SettingsHashBuilder().getHash(configFileUrl, queryString);
		return new PrivateRepositoryFeed(configFileUrl, queryString, settingsHash, opt);
	} 
	catch (IOException e) {
		log.warn("Error while reading " + queryFile.getAbsolutePath(), e);				
	}
	return null;
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:23,代码来源:DataFeedFactory.java

示例5: init

import gate.util.Files; //导入依赖的package包/类
public Resource init() throws ResourceInstantiationException {
	// check that the tokenizer is in the resource
	// directory
    ResourceData thisRD =
      (ResourceData)Gate.getCreoleRegister().get(this.getClass().getName());
    URL myCreoleXML = thisRD.getXmlFileUrl();
    if(!"file".equals(myCreoleXML.getProtocol())) {
      throw new ResourceInstantiationException(
          "Tokenizer plugin must be loaded from a file: URL");
    }
    File myCreoleXMLFile = Files.fileFromURL(myCreoleXML);
    
	tokenExecutable = myCreoleXMLFile.getParent()+ File.separator + "resources" + File.separator + "tokenise"
			+ File.separator + "token."
			+ com.digitalpebble.util.Utilities.getArch();

	// check that the file exists
	File scriptfile = new File(tokenExecutable);
	if (scriptfile.exists() == false)
		throw new ResourceInstantiationException(new Exception(
				"Executable " + scriptfile.getAbsolutePath()
						+ " does not exist"));
	return super.init();
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:25,代码来源:RASPTokenizer.java

示例6: delete

import gate.util.Files; //导入依赖的package包/类
/** Delete the data store.
  */
@Override
public void delete() throws PersistenceException {
  if(storageDir == null || ! Files.rmdir(storageDir))
    throw new PersistenceException("couldn't delete " + storageDir);

  Gate.getDataStoreRegister().remove(this);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:10,代码来源:SerialDataStore.java

示例7: write

import gate.util.Files; //导入依赖的package包/类
/**
 * Write out the (possibly modified) GAPP file to its new location.
 * 
 * @throws IOException if an I/O error occurs.
 */
public void write() throws IOException {
  finish();
  File newGappFile = Files.fileFromURL(gappFileURL);
  FileOutputStream fos = new FileOutputStream(newGappFile);
  BufferedOutputStream out = new BufferedOutputStream(fos);

  XMLOutputter outputter = new XMLOutputter(Format.getRawFormat());
  outputter.output(gappDocument, out);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:15,代码来源:GappModel.java

示例8: loadModel

import gate.util.Files; //导入依赖的package包/类
@Override
public void loadModel(URL directory, String parms) {
  if(!"file".equals(directory.getProtocol())) 
    throw new GateRuntimeException("The dataDirectory URL must be a file: URL for LibSVM");
  try {      
    File directoryFile = Files.fileFromURL(directory);
    svm_model svmModel = svm.svm_load_model(new File(directoryFile, FILENAME_MODEL).getAbsolutePath());
    System.out.println("Loaded LIBSVM model, nrclasses=" + svmModel.nr_class);
    model = svmModel;
  } catch (Exception ex) {
    throw new GateRuntimeException("Error loading the LIBSVM model from directory "+directory, ex);
  }
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:14,代码来源:EngineLibSVM.java

示例9: loadModel

import gate.util.Files; //导入依赖的package包/类
@Override
protected void loadModel(URL directoryURL, String parms) {
  ArrayList<String> finalCommand = new ArrayList<String>();
  // Instead of loading a model, this establishes a connection with the 
  // external sklearn process. 
  if(!"file".equals(directoryURL.getProtocol())) 
    throw new GateRuntimeException("The dataDirectory URL must be a file: URL for sklearn");
  File directory = Files.fileFromURL(directoryURL);
  File commandFile = findWrapperCommand(directory, true);
  String modelFileName = new File(directory,MODEL_BASENAME).getAbsolutePath();
  finalCommand.add(commandFile.getAbsolutePath());
  finalCommand.add(modelFileName);
  // if we have a shell command prepend that, and if we have shell parms too, include them
  if(shellcmd != null) {
    finalCommand.add(0,shellcmd);
    if(shellparms != null) {
      String[] sps = shellparms.trim().split("\\s+");
      int i=0; for(String sp : sps) { finalCommand.add(++i,sp); }
    }
  }
  //System.err.println("Running: "+finalCommand);
  // Create a fake Model jsut to make LF_Apply... happy which checks if this is null
  model = MODEL_INSTANCE;
  Map<String,String> env = new HashMap<>();
  env.put(ENV_WRAPPER_HOME, wrapperhome);
  process = Process4JsonStream.create(directory,env,finalCommand);
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:28,代码来源:EngineMBSklearnBase.java

示例10: loadModel

import gate.util.Files; //导入依赖的package包/类
@Override
protected void loadModel(URL directoryURL, String parms) {
  File directory = null;
  if("file".equals(directoryURL.getProtocol())) directory = Files.fileFromURL(directoryURL);
  else throw new GateRuntimeException("The dataDirectory for WekaWrapper must be a file: URL not "+directoryURL);
  ArrayList<String> finalCommand = new ArrayList<String>();
  // we need the corpus representation here! Normally this is done from loadEngine and after
  // load model, but we do it here. The load crm method only loads anything if it is still
  // null, so we will do this only once anyway.
  loadAndSetCorpusRepresentation(directoryURL);
  CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
  SimpleEntry<String,Integer> modeAndNrC = findOutMode(data);
  String mode = modeAndNrC.getKey();
  Integer nrClasses = modeAndNrC.getValue();
  // Instead of loading a model, this establishes a connection with the 
  // external wrapper process. 
  
  File commandFile = findWrapperCommand(directory, true);
  String modelFileName = new File(directory,MODEL_BASENAME).getAbsolutePath();
  finalCommand.add(commandFile.getAbsolutePath());
  finalCommand.add(modelFileName);
  finalCommand.add(mode);
  finalCommand.add(nrClasses.toString());
  // if we have a shell command prepend that, and if we have shell parms too, include them
  if(shellcmd != null) {
    finalCommand.add(0,shellcmd);
    if(shellparms != null) {
      String[] sps = shellparms.trim().split("\\s+");
      int i=0; for(String sp : sps) { finalCommand.add(++i,sp); }
    }
  }
  //System.err.println("Running: "+finalCommand);
  // Create a fake Model jsut to make LF_Apply... happy which checks if this is null
  model = MODEL_INSTANCE;
  Map<String,String> env = new HashMap<>();
  env.put(ENV_WRAPPER_HOME, wrapperhome);
  process = Process4JsonStream.create(directory,env,finalCommand);
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:39,代码来源:EngineMBPythonNetworksBase.java

示例11: afterLastDocument

import gate.util.Files; //导入依赖的package包/类
@Override
public void afterLastDocument(Controller arg0, Throwable t) {
  File outDir = Files.fileFromURL(getDataDirectory());
  
  if(!haveSequenceAlg) { 
    corpusRepresentationTarget.finish();
    Exporter.export(corpusRepresentationTarget, exporter, outDir, getInstanceType(), getAlgorithmParameters());
  } else {
    corpusRepresentationSeq.finish();
    Exporter.export(corpusRepresentationSeq, exporter, outDir, getInstanceType(), getAlgorithmParameters());
  }
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:13,代码来源:LF_Export.java

示例12: setTarget

import gate.util.Files; //导入依赖的package包/类
public void setTarget(Object target) {

    // make sure we are being given a target that we know how to display
    if(target == null) return;
    if(!(target instanceof ScriptPR)) { throw new GateRuntimeException(this
            .getClass().getName()
            + " can only be used to display "
            + ScriptPR.class.getName()
            + "\n"
            + target.getClass().getName()
            + " is not a " + ScriptPR.class.getName() + "!"); }

    // if this VR is being reused then stop listening to changes from the
    // previous target
    if(pr != null) {
      pr.removeProgressListener(this);
    }

    // store the PR we are displaying so we can keep refering to it
    pr = (ScriptPR)target;

    // get the script file or null if loaded from a non-file url
    try {
      file = Files.fileFromURL(pr.getScriptURL());
    } catch(Exception e) {
      file = null;
    }

    // get the editor to display the script
    editor.getTextEditor().setText(pr.getGroovySrc());

    // disable editing if we loaded from a URL
    editor.getTextEditor().setEditable(file != null);
    btnSave.setEnabled(false);
    btnRevert.setEnabled(false);

    // listen out for updates to the PR so we can keep in sync
    pr.addProgressListener(this);
  }
 
开发者ID:KHP-Informatics,项目名称:ADRApp,代码行数:40,代码来源:ScriptPREditor.java

示例13: instantiateStanfordParser

import gate.util.Files; //导入依赖的package包/类
private void instantiateStanfordParser()
  throws ResourceInstantiationException {
  if(stanfordParser != null) return;
  
  try {
    String filepath = Files.fileFromURL(parserFile).getAbsolutePath();
    stanfordParser = LexicalizedParser.getParserFromSerializedFile(filepath);
  }
  catch(Exception e) {
    throw new ResourceInstantiationException(e);
  }
}
 
开发者ID:vita-us,项目名称:ViTA,代码行数:13,代码来源:Parser.java

示例14: getActions

import gate.util.Files; //导入依赖的package包/类
@Override
public List<Action> getActions() {
  if (actions == null) {
    actions = new ArrayList<Action>();

    // Action 1: remove the gazbin file and re-initialize the gazetteer
    actions.add(
            new AbstractAction("Remove cache and re-initialize") {
      {
        putValue(SHORT_DESCRIPTION,
                "Remove cache and re-initialize");
        putValue(GateConstants.MENU_PATH_KEY,
                new String[]{"WTFISTHIS??????"});
      }
      private static final long serialVersionUID = 1L;

      @Override
      public void actionPerformed(ActionEvent evt) {
        File configFile = gate.util.Files.fileFromURL(getConfigFileURL());
        String configFileName = configFile.getAbsolutePath();
        String gazbinFileName = configFileName.replaceAll("(?:\\.def$|\\.defyaml)", ".gazbin");
        if (configFileName.equals(gazbinFileName)) {
          throw new GateRuntimeException("Config file must have def or defyaml extension!");
        }
        File gazbinFile = new File(gazbinFileName);
        gazbinFile.delete();
        try {
          reInit();
        } catch (ResourceInstantiationException ex) {
          throw new GateRuntimeException("Re-initialization failed",ex);
        }
      }
    });

    
  }
  return actions;
}
 
开发者ID:johann-petrak,项目名称:gateplugin-StringAnnotation,代码行数:39,代码来源:GazetteerBase.java

示例15: init

import gate.util.Files; //导入依赖的package包/类
@Override
public Resource init() {

  // create a new instance of MutationFinder using the supplied file
  finder = new MutationFinder(Files.fileFromURL(regexpURL));

  return this;
}
 
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:9,代码来源:MutationFinderPR.java


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