Java Code Examples for java.io.File

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Manager/.

Source file: AreaDatabaseManager.java

  44 
vote

@Override protected DatabaseConnection createConnection(String pluginName,File dataFolder) throws Exception {
  File configFile=new File(dataFolder,"area_sqlconfig.yml");
  YamlConfiguration config=new YamlConfiguration();
  if (!configFile.exists()) {
    DatabaseUtils.createDatabaseConfig(DatabaseType.MySQL,configFile,Core.getInstance().getDescription().getName());
    return null;
  }
  config.load(configFile);
  return new DatabaseConnection(pluginName,config.getString("Host"),config.getString("Port"),config.getString("Database"),config.getString("User"),config.getString("Password"));
}
 

Example 2

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generator/model/.

Source file: Model.java

  37 
vote

public boolean loadModel(String file) throws IOException {
  File f=new File(file);
  if (f.exists()) {
    relations.clear();
    BufferedReader r=new BufferedReader(new FileReader(f));
    readFromStream(r);
    r.close();
    return true;
  }
 else {
    System.err.println("File not found: " + file);
    return false;
  }
}
 

Example 3

From project 4308Cirrus, under directory /tendril-domain/src/test/java/edu/colorado/cs/cirrus/domain/model/.

Source file: DeviceActionQueryTest.java

  36 
vote

@Test public void canDeserializeDeviceActionQuery2(){
  Serializer serializer=new Persister();
  File source=new File("src/test/resources/QueryDeviceAction2.xml");
  try {
    DeviceActionQuery exampleUser=serializer.read(DeviceActionQuery.class,source);
    System.err.println(exampleUser);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail();
  }
}
 

Example 4

From project 4308Cirrus, under directory /tendril-domain/src/test/java/edu/colorado/cs/cirrus/domain/model/.

Source file: DeviceActionQueryTest.java

  35 
vote

@Test public void canDeserializeDeviceActionQuery1(){
  Serializer serializer=new Persister();
  File source=new File("src/test/resources/QueryDeviceAction1.xml");
  try {
    DeviceActionQuery exampleUser=serializer.read(DeviceActionQuery.class,source);
    System.err.println(exampleUser);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail();
  }
}
 

Example 5

From project ACLS-protocol-library, under directory /aclslib/src/main/java/au/edu/uq/cmm/aclslib/config/.

Source file: JsonConfigLoader.java

  35 
vote

/** 
 * Load the configuration from a file.
 * @param configFile
 * @return the configuration or null if it couldn't be found / read.
 * @throws ConfigurationException 
 */
public C loadConfiguration(String configFile) throws ConfigurationException {
  InputStream is=null;
  try {
    File cf=new File(configFile == null ? "config.json" : configFile);
    is=new FileInputStream(cf);
    return readConfiguration(is);
  }
 catch (  IOException ex) {
    throw new ConfigurationException("Cannot open file '" + configFile + "'",ex);
  }
 finally {
    closeQuietly(is);
  }
}
 

Example 6

From project AdminCmd, under directory /src/main/java/be/Balor/Tools/Files/.

Source file: FileManager.java

  35 
vote

/** 
 * To write a text file on the AdminCmd folder.
 * @param filename
 * @param toSet
 */
public void setTxtFile(final String filename,final String toSet){
  final File txt=getFile(null,filename + ".txt");
  try {
    UnicodeUtil.saveUTF8File(txt,toSet,false);
  }
 catch (  final IOException e) {
    ACLogger.severe("Can't write the file " + filename,e);
  }
}
 

Example 7

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Manager/.

Source file: TicketDatabaseManager.java

  34 
vote

@Override protected DatabaseConnection createConnection(String pluginName,File dataFolder) throws Exception {
  File configFile=new File(dataFolder,"ticket_sqlconfig.yml");
  if (configFile.exists())   return new DatabaseConnection(pluginName,DatabaseType.MySQL,new MinestarConfig(configFile));
 else {
    DatabaseUtils.createDatabaseConfig(DatabaseType.MySQL,configFile,pluginName);
    return null;
  }
}
 

Example 8

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/servlets/.

Source file: FileServlet.java

  34 
vote

private void showIdexFile(HttpServletRequest req,HttpServletResponse res,boolean headOnly,String path,String parent) throws IOException {
  if (isLogEnabled())   Utils.console("Showing index in directory " + parent);
  for (int i=0; i < DEFAULTINDEXPAGES.length; i++) {
    File indexFile=new File(parent,DEFAULTINDEXPAGES[i]);
    if (indexFile.exists()) {
      serveFile(req,res,headOnly,indexFile);
      return;
    }
  }
  serveDirectory(req,res,headOnly,path,new File(parent));
}
 

Example 9

From project Aardvark, under directory /aardvark/src/main/test/gw/vark/it/.

Source file: AcceptanceITCase.java

  34 
vote

public void testDirectoryWithNoSpecifiedBuildVark(){
  TestOutputHandler stdOut=new TestOutputHandler("stdout");
  TestOutputHandler stdErr=new TestOutputHandler("stderr");
  File merpVark=new File(_sampleprojectDir,"merp.vark");
  runAardvark(_sampleprojectDir,merpVark,"",stdOut,stdErr);
  assertThatOutput(stdErr).contains("Specified vark buildfile " + merpVark + " doesn't exist");
}
 

Example 10

From project Aardvark, under directory /aardvark/src/main/test/gw/vark/it/.

Source file: AssemblyStructureITCase.java

  34 
vote

@Test public void licenseExists(){
  File assemblyDir=ITUtil.getAssemblyDir();
  File licenseFile=new File(assemblyDir,"LICENSE");
  assertThat(licenseFile).exists();
  assertThat(licenseFile).isFile();
}
 

Example 11

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.webapp/src/org/eclipse/acceleo/tutorial/webapp/main/.

Source file: Webapp.java

  34 
vote

/** 
 * This can be used to launch the generation from a standalone application.
 * @param args Arguments of the generation.
 * @generated
 */
public static void main(String[] args){
  try {
    if (args.length < 2) {
      System.out.println("Arguments not valid : {model, folder}.");
    }
 else {
      URI modelURI=URI.createFileURI(args[0]);
      File folder=new File(args[1]);
      List<String> arguments=new ArrayList<String>();
      Webapp generator=new Webapp(modelURI,folder,arguments);
      for (int i=2; i < args.length; i++) {
        generator.addPropertiesFile(args[i]);
      }
      generator.doGenerate(new BasicMonitor());
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 12

From project AceWiki, under directory /src/ch/uzh/ifi/attempto/acewiki/core/.

Source file: FileBasedStorage.java

  34 
vote

public void save(User user){
  try {
    String n=user.getUserBase().getOntology().getName();
    File d=new File(dir + "/" + n+ ".users");
    if (!d.exists())     d.mkdir();
    FileOutputStream out=new FileOutputStream(new File(dir + "/" + n+ ".users"+ "/"+ user.getId()));
    out.write(serialize(user).getBytes("UTF-8"));
    out.close();
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
}
 

Example 13

From project activejdbc, under directory /activejdbc-instrumentation/src/main/java/org/javalite/instrumentation/.

Source file: Instrumentation.java

  34 
vote

public void instrument(){
  if (outputDirectory == null) {
    throw new RuntimeException("Property 'outputDirectory' must be provided");
  }
  try {
    System.out.println("**************************** START INSTRUMENTATION ****************************");
    System.out.println("Directory: " + outputDirectory);
    InstrumentationModelFinder mf=new InstrumentationModelFinder();
    File target=new File(outputDirectory);
    mf.processDirectoryPath(target);
    ModelInstrumentation mi=new ModelInstrumentation();
    for (    CtClass clazz : mf.getModels()) {
      mi.instrument(clazz);
    }
    generateModelsFile(mf.getModels(),target);
    System.out.println("**************************** END INSTRUMENTATION ****************************");
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 14

From project activemq-apollo, under directory /apollo-itests/src/test/java/org/apache/activemq/apollo/.

Source file: JmsTestBase.java

  34 
vote

public void startBroker(){
  if (System.getProperty("basedir") == null) {
    File file=new File(".");
    System.setProperty("basedir",file.getAbsolutePath());
  }
  broker=protocol.create(brokerConfig);
  protocol.start(broker);
}
 

Example 15

From project Activiti-KickStart, under directory /activiti-kickstart-java/src/test/java/org/activiti/kickstart/.

Source file: KickstartTest.java

  34 
vote

private void writeToFile(final String file,final byte[] data) throws IOException {
  File f=new File(file);
  FileOutputStream fout=new FileOutputStream(f);
  fout.write(data);
  fout.flush();
  fout.close();
}
 

Example 16

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/builder/.

Source file: D80ReportView.java

  34 
vote

private void saveD80ToHtmlFile(String fileName) throws IOException {
  File f=new File(fileName);
  if (f.exists()) {
    f.delete();
  }
  OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream(f));
  osw.write(d_d80Report);
  osw.close();
}
 

Example 17

From project addis, under directory /application/src/test/java/org/drugis/addis/gui/.

Source file: MainTest.java

  34 
vote

@Test public void testSaveDomainAs() throws IOException {
  File tmpFile=File.createTempFile("data",".addis");
  final String expectedDisplayName=tmpFile.getName().replace(".addis","");
  Main main=new Main(new String[]{},true);
  PropertyChangeListener listener=JUnitUtil.mockStrictListener(main,Main.PROPERTY_DISPLAY_NAME,null,expectedDisplayName);
  main.addPropertyChangeListener(listener);
  main.saveDomainToFile(tmpFile.getAbsolutePath());
  EasyMock.verify(listener);
  assertEquals(expectedDisplayName,main.getDisplayName());
  assertEquals(tmpFile.getAbsolutePath(),main.getCurFilename());
  assertNotNull(main.getDomain());
  assertFalse(main.getDomainChangedModel().getValue());
}
 

Example 18

From project AdminCmd, under directory /src/main/java/lib/SQL/PatPeter/SQLibrary/.

Source file: SQLite.java

  34 
vote

public SQLite(final Logger log,final String prefix,final String name,final String location){
  super(log,prefix,"[SQLite] ");
  this.name=name;
  this.location=location;
  final File folder=new File(this.location);
  if (this.name.contains("/") || this.name.contains("\\") || this.name.endsWith(".db")) {
    this.writeError("The database name cannot contain: /, \\, or .db",true);
  }
  if (!folder.exists()) {
    folder.mkdir();
  }
  sqlFile=new File(folder,name + ".db");
}
 

Example 19

From project AdServing, under directory /modules/db/src/main/java/net/mad/ads/db/db/index/impl/.

Source file: AdDBLuceneIndex.java

  34 
vote

@Override public void open() throws IOException {
  if (addb.manager.getContext().useRamOnly) {
    index=new RAMDirectory();
  }
 else {
    if (Strings.isNullOrEmpty(addb.manager.getContext().datadir)) {
      throw new IOException("temp directory can not be empty");
    }
    String dir=addb.manager.getContext().datadir;
    if (!dir.endsWith("/") || !dir.endsWith("\\")) {
      dir+="/";
    }
    File temp=new File(dir + "index");
    if (!temp.exists()) {
      temp.mkdirs();
    }
    index=FSDirectory.open(temp);
  }
  IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_40,new KeywordAnalyzer());
  config.setOpenMode(OpenMode.CREATE_OR_APPEND);
  writer=new IndexWriter(index,config);
  nrt_manager=new NRTManager(new NRTManager.TrackingIndexWriter(writer),null);
}
 

Example 20

From project AdServing, under directory /modules/db/src/main/java/net/mad/ads/db/db/store/impl/.

Source file: AdDBBDBStore.java

  34 
vote

@Override public void open() throws IOException {
  if (Strings.isNullOrEmpty(addb.manager.getContext().datadir)) {
    throw new IOException("temp directory can not be empty");
  }
  String dir=addb.manager.getContext().datadir;
  if (!dir.endsWith("/") || !dir.endsWith("\\")) {
    dir+="/";
  }
  File temp=new File(dir + "store");
  if (!temp.exists()) {
    temp.mkdirs();
  }
  EnvironmentConfig envConfig=new EnvironmentConfig();
  envConfig.setTransactional(false);
  envConfig.setAllowCreate(true);
  env=new Environment(temp,envConfig);
  DatabaseConfig dbConfig=new DatabaseConfig();
  dbConfig.setAllowCreate(true);
  Database catalogDb=env.openDatabase(null,"catalog",dbConfig);
  catalog=new StoredClassCatalog(catalogDb);
  StringBinding keyBinding=new StringBinding();
  SerialBinding<AdDefinition> valueBinding=new SerialBinding<AdDefinition>(catalog,AdDefinition.class);
  this.db=env.openDatabase(null,"banner.db",dbConfig);
  this.banners=new StoredSortedMap<String,AdDefinition>(db,keyBinding,valueBinding,true);
}
 

Example 21

From project acceleo-modules, under directory /ecore-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.ecore.gen.scala/src/com/github/sbegaudeau/acceleo/modules/ecore/gen/scala/main/.

Source file: EcoreGenScala.java

  33 
vote

/** 
 * This can be used to launch the generation from a standalone application.
 * @param args Arguments of the generation.
 * @generated
 */
public static void main(String[] args){
  try {
    if (args.length < 2) {
      System.out.println("Arguments not valid : {model, folder}.");
    }
 else {
      URI modelURI=URI.createFileURI(args[0]);
      File folder=new File(args[1]);
      List<String> arguments=new ArrayList<String>();
      EcoreGenScala generator=new EcoreGenScala(modelURI,folder,arguments);
      for (int i=2; i < args.length; i++) {
        generator.addPropertiesFile(args[i]);
      }
      generator.doGenerate(new BasicMonitor());
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 22

From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala/src/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/main/.

Source file: Workflow.java

  33 
vote

/** 
 * This can be used to launch the generation from a standalone application.
 * @param args Arguments of the generation.
 * @generated
 */
public static void main(String[] args){
  try {
    if (args.length < 2) {
      System.out.println("Arguments not valid : {model, folder}.");
    }
 else {
      URI modelURI=URI.createFileURI(args[0]);
      File folder=new File(args[1]);
      List<String> arguments=new ArrayList<String>();
      Workflow generator=new Workflow(modelURI,folder,arguments);
      for (int i=2; i < args.length; i++) {
        generator.addPropertiesFile(args[i]);
      }
      generator.doGenerate(new BasicMonitor());
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 23

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.extension/src/org/eclipse/acceleo/tutorial/extension/main/.

Source file: Extension.java

  33 
vote

/** 
 * This can be used to launch the generation from a standalone application.
 * @param args Arguments of the generation.
 * @generated
 */
public static void main(String[] args){
  try {
    if (args.length < 2) {
      System.out.println("Arguments not valid : {model, folder}.");
    }
 else {
      URI modelURI=URI.createFileURI(args[0]);
      File folder=new File(args[1]);
      List<String> arguments=new ArrayList<String>();
      Extension generator=new Extension(modelURI,folder,arguments);
      for (int i=2; i < args.length; i++) {
        generator.addPropertiesFile(args[i]);
      }
      generator.doGenerate(new BasicMonitor());
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 24

From project accesointeligente, under directory /src/org/accesointeligente/server/robots/.

Source file: ResponseChecker.java

  33 
vote

private Attachment cloneAttachment(Attachment attachment){
  org.hibernate.Session hibernate=HibernateUtil.getSession();
  hibernate.beginTransaction();
  Attachment newAttachment=new Attachment();
  hibernate.save(newAttachment);
  hibernate.getTransaction().commit();
  File oldFile=new File(ApplicationProperties.getProperty("attachment.directory") + attachment.getId().toString() + "/"+ attachment.getName());
  File newDirectory=new File(ApplicationProperties.getProperty("attachment.directory") + newAttachment.getId().toString());
  try {
    newDirectory.mkdir();
    FileUtils.copyFileToDirectory(oldFile,newDirectory);
  }
 catch (  Exception e) {
    hibernate=HibernateUtil.getSession();
    hibernate.beginTransaction();
    hibernate.delete(attachment);
    hibernate.getTransaction().commit();
    logger.error("Error saving " + newDirectory.getAbsolutePath() + "/"+ attachment.getName(),e);
    return null;
  }
  String baseUrl=ApplicationProperties.getProperty("attachment.baseurl") + newAttachment.getId().toString();
  newAttachment.setName(attachment.getName());
  newAttachment.setType(attachment.getType());
  newAttachment.setUrl(baseUrl + "/" + newAttachment.getName());
  hibernate=HibernateUtil.getSession();
  hibernate.beginTransaction();
  hibernate.update(newAttachment);
  hibernate.getTransaction().commit();
  return newAttachment;
}
 

Example 25

From project AceWiki, under directory /src/ch/uzh/ifi/attempto/acewiki/core/.

Source file: FileBasedStorage.java

  33 
vote

public UserBase getUserBase(Ontology ontology){
  UserBase userBase=userBases.get(ontology.getName());
  if (userBase == null) {
    userBase=new UserBase(ontology,this);
    userBases.put(ontology.getName(),userBase);
    File userDir=new File(dir + "/" + ontology.getName()+ ".users");
    if (userDir.exists()) {
      for (      File file : userDir.listFiles()) {
        User user=loadUser(userBase,file);
        userBase.addUser(user);
      }
    }
 else {
      userDir.mkdir();
    }
  }
  return userBase;
}
 

Example 26

From project activejdbc, under directory /activejdbc-instrumentation/src/main/java/org/javalite/instrumentation/.

Source file: ActiveJdbcInstrumentationPlugin.java

  33 
vote

private void instrument(String instrumentationDirectory) throws MalformedURLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  if (!new File(instrumentationDirectory).exists()) {
    getLog().info("Instrumentation: directory " + instrumentationDirectory + " does not exist, skipping");
    return;
  }
  ClassLoader realmLoader=getClass().getClassLoader();
  URL outDir=new File(instrumentationDirectory).toURL();
  Method addUrlMethod=realmLoader.getClass().getSuperclass().getDeclaredMethod("addURL",URL.class);
  addUrlMethod.setAccessible(true);
  addUrlMethod.invoke(realmLoader,outDir);
  Instrumentation instrumentation=new Instrumentation();
  instrumentation.setOutputDirectory(instrumentationDirectory);
  instrumentation.instrument();
}
 

Example 27

From project activemq-apollo, under directory /apollo-distro/src/main/release/examples/java-embedded-broker/src/main/java/example/.

Source file: EmbeddedBroker.java

  33 
vote

public static void main(String[] args) throws Exception {
  Broker broker=new Broker();
  broker.setTmp(new File("./tmp"));
  broker.setConfig(createConfig());
  System.out.println("Starting the broker.");
  broker.start(new Runnable(){
    public void run(){
      System.out.println("The broker has now started.");
      System.out.println("Press enter to change the broker port...");
    }
  }
);
  System.in.read();
  System.out.println("Updating the broker configuration.");
  broker.update(createUpdate(),new Runnable(){
    public void run(){
      System.out.println("The configuration has been applied.");
      System.out.println("Press enter to stop the broker...");
    }
  }
);
  System.in.read();
  System.out.println("Stopping the broker.");
  broker.stop(new Runnable(){
    public void run(){
      System.out.println("The broker has now stopped.");
    }
  }
);
}