Java Code Examples for java.io.FileWriter.append()

The following are Jave code examples for showing how to use append() of the java.io.FileWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AndiCar   File: GPSTrackService.java   View Source Code Vote up 6 votes
private void createGOPFile(String fileName) throws IOException {
    File gpsTrackDetailGOPFile = FileUtils.createGpsTrackDetailFile(GOP_FORMAT, fileName);
    gpsTrackDetailGOPFileWriter = new FileWriter(gpsTrackDetailGOPFile);

    //create the header
    gpsTrackDetailGOPFileWriter.append("LatitudeE6,LongitudeE6,PointType\n");

    ContentValues cvData = new ContentValues();
    cvData.put(DBAdapter.COL_NAME_GPSTRACKDETAIL__GPSTRACK_ID, gpsTrackId);
    cvData.put(DBAdapter.COL_NAME_GPSTRACKDETAIL__FILEFORMAT, GOP_FORMAT);
    cvData.put(DBAdapter.COL_NAME_GPSTRACKDETAIL__FILE, gpsTrackDetailGOPFile.getAbsolutePath());
    mDbAdapter.createRecord(DBAdapter.TABLE_NAME_GPSTRACKDETAIL, cvData);

    gpsTrackDetailGOPFileWriter.flush();

    if (isEnableDebugLog) {
        logDebugInfo(debugLogFile, "createGOPFile: File created. gpsTrackDetailGOPFile = " + fileName, null);
    }
}
 
Example 2
Project: StackNet   File: PythonGenericClassifier.java   View Source Code Vote up 6 votes
/**
* 
* @param filename : the configuration file name for required to run python from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will be saved
* @param columns : Number of columns in the data
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=predict\n");
	    writer.append("columns=" + columns+ "\n");				
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				
	    writer.append("prediction=" +predictionfile+ "\n");	
	    if (this.verbose){
	    	writer.append("verbose=1" +  "\n");
	    }else {
	    	writer.append("verbose=0" +  "\n");			    	
	    }				    
	   
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 3
Project: AndiCar   File: GPSTrackService.java   View Source Code Vote up 6 votes
private static void logDebugInfo(File debugLogFile, String msg, @Nullable Throwable t) {
    Log.d(LOG_TAG, msg);

    try {
        FileWriter debugLogFileWriter = new FileWriter(debugLogFile, true);
        msg = Utils.getFormattedDateTime(System.currentTimeMillis(), true) + " -> " + msg;
        debugLogFileWriter.append("\n").append(msg).append("\n");
        if (t != null) {
            debugLogFileWriter.append(Utils.getStackTrace(t));
        }
        debugLogFileWriter.flush();
        debugLogFileWriter.close();
    }
    catch (IOException ignored) {
    }
}
 
Example 4
Project: StackNet   File: SklearnDecisionTreeClassifier.java   View Source Code Vote up 6 votes
/**
* 
* @param filename : the configuration file name for required to run python from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will be saved
* @param columns : Number of columns in the data
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=predict\n");
	    writer.append("columns=" + columns+ "\n");				
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				
	    writer.append("prediction=" +predictionfile+ "\n");				    
	   
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 5
Project: Embeddable-BSBM   File: TestDriver.java   View Source Code Vote up 6 votes
public void runMT() {
    ClientManager manager = new ClientManager(parameterPool, this);

    manager.createClients();
    manager.startWarmup();
    manager.startRun();
    logger.info(printResults(true));
    try {
        FileWriter resultWriter = new FileWriter(xmlResultFile);
        resultWriter.append(printXMLResults(true));
        resultWriter.flush();
        resultWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 6
Project: StackNet   File: SklearnsvmRegressor.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the configuration file name for required to run python from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will be saved
* @param columns : Number of columns in the data
*/
 
 private void create_config_file_pred(String filename , String datset, String model, String predictionfile, int columns){

	try{  // Catch errors in I/O if necessary.
		  // Open a file to write to.
			String saveFile = filename;
			
			FileWriter writer = new FileWriter(saveFile);
		writer.append("task=predict\n");
	    writer.append("columns=" + columns+ "\n");				
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("use_scale=" + this.use_scale+ "\n");				    
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				
	    writer.append("prediction=" +predictionfile+ "\n");	
	    if (this.verbose){
	    	writer.append("verbose=1" +  "\n");
	    }else {
	    	writer.append("verbose=0" +  "\n");			    	
	    }						    
			writer.close();

    	} catch (Exception e) {
    		throw new IllegalStateException(" failed to write the config file at: " + filename);
    	}   
 }
 
Example 7
Project: aliyun-maxcompute-data-collectors   File: ManagerCompatExport.java   View Source Code Vote up 5 votes
public void addToReport(MSSQLTestData td, Object result) {
  try {
    FileWriter fr = new FileWriter(getOutputFileName(), true);
    String offset = td.getData(KEY_STRINGS.OFFSET);
    String dt = td.getDatatype();
    String res = "_";
    if (result == null) {
      res = "Success";
    } else {
      try {
        res = "FAILED "
            + removeNewLines(((AssertionError) result)
                .getMessage());

      } catch (Exception ae) {
        if (result instanceof Exception) {
          res = "FAILED "
              + removeNewLines(((Exception) result)
                  .getMessage());
        } else {
          res = "FAILED " + result.toString();
        }
      }
    }

    fr.append(offset + "\t" + "\t" + res + "\t" + dt + "\t"
        + removeNewLines(td.toString()) + "\n");
    fr.close();
  } catch (Exception e) {
    LOG.error(StringUtils.stringifyException(e));
  }

}
 
Example 8
Project: incubator-netbeans   File: GoldenFileTestBase.java   View Source Code Vote up 5 votes
protected void assertContents(CharSequence sb) throws IOException {
    File out = new File(getWorkDir(), fname + ".parsed");
    FileWriter wr = new FileWriter(out);
    wr.append(sb);
    wr.close();
    
    assertFile(out, getGoldenFile(fname + ".pass"), new File(getWorkDir(), fname + ".diff"));
}
 
Example 9
Project: StackNet   File: LightgbmRegressor.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the conifiguration file name for required to run xgboost from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will eb saved
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
	    writer.append("objective=" + this.Objective+ "\n");
	    writer.append("is_sparse=true" + "\n");				  
	    writer.append("num_threads=" + this.threads + "\n");
	    if (this.verbose){
	    	writer.append("verbosity=1" +  "\n");
	    }else {
	    	writer.append("verbosity=0" +  "\n");			    	
	    }
	    
	    //file details
	    writer.append(datset+ "\n");
	    writer.append( model+ "\n");
	    writer.append( "output_result=" + predictionfile + "\n");
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 10
Project: StackNet   File: XgboostRegressor.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the conifiguration file name for required to run xgboost from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will eb saved
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
	    writer.append("objective=" + this.Objective+ "\n");
	    writer.append("nthread=" + this.threads + "\n");
	    writer.append("max_leaves=" + this.max_leaves + "\n");
	    writer.append("save_period=0" + "\n");
	    if (this.verbose){
	    	writer.append("silent=0" +  "\n");
	    }else {
	    	writer.append("silent=1" +  "\n");			    	
	    }
	    
	    //file details
	    writer.append(datset+ "\n");
	    writer.append( model+ "\n");
	    writer.append( "name_pred=" + predictionfile + "\n");
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 11
Project: mysql-jdbc-benchmark   File: ReportCreator.java   View Source Code Vote up 5 votes
private void writeIterationReport(FileWriter writer, IterationReport report) {
    try {
        writer.append("Iteration " + report.getIteration() + ":" + LINE_SEPARATOR);
        writer.append(INDENT + "Start Time: " + report.getStart().format(DateTimeFormatter.ISO_DATE_TIME) + LINE_SEPARATOR);
        writer.append(INDENT + "End Time: " + report.getEnd().format(DateTimeFormatter.ISO_DATE_TIME) + LINE_SEPARATOR);
        writer.append(INDENT + "Duration: " + report.getDuration().toMillis() + "ms" + LINE_SEPARATOR + LINE_SEPARATOR);
    }catch (IOException e){
        throw new WrappedIOException(e);
    }
}
 
Example 12
Project: monarch   File: MTableDataCommandResult.java   View Source Code Vote up 5 votes
public void writeToFile(int startCount, int endCount, String fileName) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("MTableDataCommandResult.writeToFile startCount = " + startCount + " endCount = "
        + endCount + " fileName = " + fileName);
  }
  boolean isFTable = this.isFTable;

  FileWriter writer = new FileWriter(fileName, true);
  for (int i = startCount; i <= endCount; i++) {
    if (i >= this.resultValues.size()) {
      break;
    }
    Row row = resultValues.get(i);
    if (i == 0) {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("#"); // This is for header (comment in csv).
      if (!isFTable) {
        stringBuilder.append("RowID");
      }
      List<Cell> cells = row.getCells();
      for (int j = 0; j < cells.size(); j++) {
        if (isFTable) {
          if (j > 0) {
            stringBuilder.append(",");
          }
        } else {
          stringBuilder.append(",");
        }
        stringBuilder.append(Bytes.toString(cells.get(j).getColumnName()));
        stringBuilder.append(":");
        stringBuilder.append(cells.get(j).getColumnType().toString());
      }
      writer.append(stringBuilder.toString());
      writer.append('\n');
      writer.flush();
    }
    toMResultCSV(row, writer, isFTable);
  }
  writer.close();
}
 
Example 13
Project: StackNet   File: SklearnRandomForestClassifier.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the configuration file name for required to run python from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will be saved
* @param columns : Number of columns in the data
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=predict\n");
	    writer.append("columns=" + columns+ "\n");				
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				
	    writer.append("prediction=" +predictionfile+ "\n");	
	    if (this.verbose){
	    	writer.append("verbose=1" +  "\n");
	    }else {
	    	writer.append("verbose=0" +  "\n");			    	
	    }				    
	   
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 14
Project: aliyun-maxcompute-data-collectors   File: SQLServerDatatypeImportSequenceFileManualTest.java   View Source Code Vote up 5 votes
public  synchronized void addToReport(MSSQLTestData td, Object result) {
  System.out.println("called");
  try {
    FileWriter fr = new FileWriter(getResportFileName(), true);
    String offset = td.getData(KEY_STRINGS.OFFSET);
    String res = "_";
    if (result == null) {
    res = "Success";
  } else {
    try {
    res = "FAILED "
    + removeNewLines(((AssertionError) result)
    .getMessage());
    } catch (Exception ae) {
      if (result instanceof Exception
        && ((Exception) result) != null) {
        res = "FAILED "
        + removeNewLines(((Exception) result)
        .getMessage());
      } else {
        res = "FAILED " + result.toString();
      }
    }
  }

  fr.append(offset + "\t" + res + "\n");
  fr.close();
  } catch (Exception e) {
    LOG.error(StringUtils.stringifyException(e));
  }
}
 
Example 15
Project: StackNet   File: SklearnDecisionTreeRegressor.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the conifiguration file name for required to run xgboost from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param columns : Number of columns in the data
*/
 private void create_config_file(String filename , String datset, String model, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
	
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=train\n");
	    writer.append("columns=" + columns+ "\n");					
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				    
	    writer.append("criterion=" + this.criterion  + "\n");
	    writer.append("max_depth=" +this.max_depth + "\n");
	    writer.append("max_features=" + this.max_features + "\n");
	    writer.append("max_leaf_nodes=" + this.max_leaf_nodes+ "\n");
	    writer.append("min_impurity_split=" + this.min_impurity_split + "\n");
	    writer.append("min_samples_leaf=" + this.min_samples_leaf + "\n");
	    writer.append("min_samples_split=" + this.min_samples_split  + "\n");
	    writer.append("min_weight_fraction_leaf=" + this.min_weight_fraction_leaf + "\n");
	    writer.append("max_depth=" +  this.max_depth + "\n");
	    writer.append("random_state=" +  this.seed + "\n");	    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
 }
 
Example 16
Project: StackNet   File: KerasnnClassifier.java   View Source Code Vote up 5 votes
/**
* 
* @param filename : the configuration file name for required to run python from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param predictionfile : where the predictions will be saved
* @param columns : Number of columns in the data
*/
private void create_config_file_pred(String filename , String datset, String model, String predictionfile, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=predict\n");
	    writer.append("columns=" + columns+ "\n");				
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("standardize=" + this.standardize+ "\n");
	    writer.append("batch_size=" + this.batch_size + "\n");			    
	    writer.append("use_log1p=" + this.use_log1p+ "\n");			    
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				
	    writer.append("prediction=" +predictionfile+ "\n");	
	    if (this.verbose){
	    	writer.append("verbose=1" +  "\n");
	    }else {
	    	writer.append("verbose=0" +  "\n");			    	
	    }				    
	   
    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
}
 
Example 17
Project: incubator-netbeans   File: TestUtilHid.java   View Source Code Vote up 4 votes
public void serialize(String path, String tab, PrintWriter pw, File baseFolder) throws IOException {
    if (!getName().isEmpty()) {
        String n = getName();
        if (isLeaf()) {
            pw.print(tab+"<file name=\""+n + "\"");
        } else {
            pw.print(tab+"<folder name=\""+n + "\"");
        }
        String urlVal = null;

        if (fileContents != null) {
            urlVal = (path + getName()).replaceAll("/", "-");
            File f = new File(baseFolder, urlVal);
            FileWriter wr = new FileWriter(f);
            wr.append(fileContents);
            wr.close();
        } else if (contentURL != null) {
            urlVal = contentURL.toExternalForm();
        }
        if (urlVal != null) {
            pw.print(" url=\"" + urlVal + "\"");
        }
        pw.print(">");

        for (String s : attributeContents.keySet()) {
            pw.print("\n" + tab + "    <attr name=\"" + s + "\" " + 
                    attributeTypes.get(s) + "=\"" + attributeContents.get(s) + "\"/>");
        }
        pw.println();
    }
    String newPath = path + getName();
    if (!newPath.isEmpty()) {
        newPath = newPath + "/";
    }
    for (ResourceElement res : children.values()) {
        res.serialize(newPath, tab + "  ", pw, baseFolder);
    }
    if (!getName().isEmpty()) {
        if (isLeaf()) {
            pw.println(tab+"</file>" );                            
        } else {
            pw.println(tab+"</folder>" );            
        }
    }
}
 
Example 18
Project: StackNet   File: SklearnMLPRegressor.java   View Source Code Vote up 4 votes
/**
* 
* @param filename : the conifiguration file name for required to run xgboost from the command line
* @param datset : the dataset to be used
* @param model : model dump name
* @param columns : Number of columns in the data
*/
 private void create_config_file(String filename , String datset, String model, int columns){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
	
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("task=train\n");
	    writer.append("columns=" + columns+ "\n");					
	    writer.append("usedense=" + this.use_dense+ "\n");	
	    writer.append("standardize=" + this.standardize+ "\n");	
	    writer.append("use_log1p=" + this.use_log1p+ "\n");				    
	    writer.append("model=" +model+ "\n");	
	    writer.append("data=" +datset+ "\n");				    
	    writer.append("alpha=" + this.alpha+ "\n");
	    writer.append("momentum=" + this.momentum  + "\n");
	    writer.append("max_iter=" +this.epochs + "\n");
	    writer.append("batch_size=" + this.batch_size + "\n");
	    writer.append("validation_fraction=" + this.validation_split + "\n");
	    writer.append("random_state=" + this.seed  + "\n");
	    writer.append("learning_rate_init=" + this.learning_rate_init + "\n");
	    writer.append("shuffle=" + this.shuffle + "\n");
	    writer.append("hidden_layer_sizes=" + this.hidden + "\n");
	    writer.append("tol=" +  this.tol + "\n");
	    writer.append("learning_rate=" +  this.learning_rate + "\n");		    
	    writer.append("activation=" + this.activation + "\n");
	    writer.append("solver=" +  this.optimizer + "\n");
	    writer.append("epsilon=" +  this.epsilon + "\n");			    
	    if (this.verbose){
	    	writer.append("verbose=1" +  "\n");
	    }else {
	    	writer.append("verbose=0" +  "\n");			    	
	    }		    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
 }
 
Example 19
Project: StackNet   File: XgboostClassifier.java   View Source Code Vote up 4 votes
/**
* 
* @param filename : the conifiguration file name for required to run xgboost from the command line
* @param datset : the dataset to be used
* @param model : model dump name
*/
 private void create_config_file(String filename , String datset, String model){

try{  // Catch errors in I/O if necessary.
	  // Open a file to write to.
		String saveFile = filename;
		
		FileWriter writer = new FileWriter(saveFile);
		writer.append("booster=" + this.booster + "\n");
	    writer.append("objective=" + this.Objective+ "\n");
	    if (this.Objective.equals("multi:softprob")){
	    	writer.append("num_class=" + this.n_classes  + "\n"); 
	    }
	    writer.append("eta=" + this.eta  + "\n");
	    writer.append("gamma=" +this.gamma + "\n");
	    writer.append("min_child_weight=" + this.min_child_weight + "\n");
	    writer.append("colsample_bytree=" + this.colsample_bytree+ "\n");
	    writer.append("colsample_bylevel=" + this.colsample_bylevel + "\n");
	    writer.append("subsample=" + this.subsample + "\n");
	    writer.append("max_delta_step=" + this.max_delta_step  + "\n");
	    writer.append("lambda=" + this.lambda + "\n");
	    writer.append("alpha=" + this.alpha + "\n");
	    writer.append("scale_pos_weight=" + this.scale_pos_weight + "\n");
	    writer.append("max_depth=" +  this.max_depth + "\n");
	    writer.append("nthread=" + this.threads + "\n");
	    writer.append("num_round=" +  this.num_round + "\n");
	    writer.append("seed=" +  this.seed + "\n");				    
	    writer.append("max_leaves=" + this.max_leaves + "\n");
	    writer.append("save_period=0" + "\n");
	    if (this.verbose){
	    	writer.append("silent=0" +  "\n");
	    }else {
	    	writer.append("silent=1" +  "\n");			    	
	    }
	    //file details
	    writer.append(datset+ "\n");
	    writer.append( model+ "\n");			    
		writer.close();

   	} catch (Exception e) {
   		throw new IllegalStateException(" failed to write the config file at: " + filename);
   	}   
 }
 
Example 20
Project: androidtools   File: DiskLogStrategy.java   View Source Code Vote up 2 votes
/**
 * This is always called on a single background thread.
 * Implementing classes must ONLY write to the fileWriter and nothing more.
 * The abstract class takes care of everything else including close the stream and catching IOException
 *
 * @param fileWriter an instance of FileWriter already initialised to the correct file
 */
private void writeLog(FileWriter fileWriter, String content) throws IOException {
  fileWriter.append(content);
}