List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:com.linkedin.pinot.perf.ForwardIndexReaderBenchmark.java
public static void multiValuedReadBenchMarkV1(File file, int numDocs, int totalNumValues, int maxEntriesPerDoc, int columnSizeInBits) throws Exception { System.out.println("******************************************************************"); System.out.println("Analyzing " + file.getName() + " numDocs:" + numDocs + ", totalNumValues:" + totalNumValues + ", maxEntriesPerDoc:" + maxEntriesPerDoc + ", numBits:" + columnSizeInBits); long start, end; boolean readFile = true; boolean randomRead = true; boolean contextualRead = true; boolean signed = false; boolean isMmap = false; PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "benchmarking"); BaseSingleColumnMultiValueReader reader = new com.linkedin.pinot.core.io.reader.impl.v1.FixedBitMultiValueReader( heapBuffer, numDocs, totalNumValues, columnSizeInBits, signed); int[] intArray = new int[maxEntriesPerDoc]; File outfile = new File("/tmp/" + file.getName() + ".raw"); FileWriter fw = new FileWriter(outfile); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray); StringBuilder sb = new StringBuilder(); String delim = ""; for (int j = 0; j < length; j++) { sb.append(delim);//from w ww. j a va2 s . co m sb.append(intArray[j]); delim = ","; } fw.write(sb.toString()); fw.write("\n"); } fw.close(); // sequential read if (readFile) { DescriptiveStatistics stats = new DescriptiveStatistics(); RandomAccessFile raf = new RandomAccessFile(file, "rw"); ByteBuffer buffer = ByteBuffer.allocateDirect((int) file.length()); raf.getChannel().read(buffer); for (int run = 0; run < MAX_RUNS; run++) { long length = file.length(); start = System.currentTimeMillis(); for (int i = 0; i < length; i++) { byte b = buffer.get(i); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v1 multi value read bytes stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); raf.close(); } if (randomRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v1 multi value sequential read one stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } if (contextualRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { MultiValueReaderContext context = (MultiValueReaderContext) reader.createContext(); start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray, context); } end = System.currentTimeMillis(); // System.out.println("RUN:" + run + "Time:" + (end-start)); stats.addValue((end - start)); } System.out.println("v1 multi value sequential read one with context stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } reader.close(); heapBuffer.close(); System.out.println("******************************************************************"); }
From source file:AIR.ResourceBundler.Console.ResourcesBuilder.java
private static void writeFileHeader(FileWriter sw, String filePath) throws IOException { File scriptInfo = new File(filePath); // get file crc String crcResult = ""; FileInputStream fs = new FileInputStream(filePath); byte[] bb = new byte[4]; int i = fs.hashCode(); for (int k = 3, j = 0; k >= 0; k--, j += 8) { bb[k] = (byte) (i >> j); }/*w w w . ja va 2 s .c o m*/ for (byte b : bb) crcResult += String.format("%2X", b).toLowerCase(); // write out script info String resourceFile = Path.getFileName(filePath); sw.write(String.format("/* SOURCE FILE: %s (%s) %s */\n", resourceFile, crcResult, scriptInfo.lastModified())); sw.write("\n"); }
From source file:doc.doclets.WorkbenchHelpDoclet.java
private static void _writeAttrDoc(final String className, final String documentation) throws IOException { String fileBaseName = className + "_attributes.html"; String fileName = null;//from ww w . jav a2s. c om if (_outputDirectory != null) { fileName = _outputDirectory + File.separator + "html" + File.separator + fileBaseName; } else { fileName = fileBaseName; } // If necessary, create the directory. final File directoryFile = new File(fileName).getParentFile(); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created."); } } System.out.println("Creating " + fileName); final FileWriter writer = new FileWriter(fileName); try { writer.write(documentation); } finally { writer.close(); } }
From source file:doc.doclets.WorkbenchHelpDoclet.java
private static void _writeIndex(final String indexText) throws IOException { String fileBaseName = "index.xml"; String fileName = null;/*from w w w.ja v a2 s .com*/ if (_outputDirectory != null) { fileName = _outputDirectory + File.separator + fileBaseName; } else { fileName = fileBaseName; } // If necessary, create the directory. final File directoryFile = new File(fileName).getParentFile(); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created."); } } System.out.println("Creating " + fileName); final FileWriter writer = new FileWriter(fileName); try { writer.write(indexText); } finally { writer.close(); } }
From source file:doc.doclets.WorkbenchHelpDoclet.java
private static void _writeTOC(final String indexText) throws IOException { String fileBaseName = "passerelle.xml"; String fileName = null;/*w ww. j av a 2 s . c o m*/ if (_outputDirectory != null) { fileName = _outputDirectory + File.separator + fileBaseName; } else { fileName = fileBaseName; } // If necessary, create the directory. final File directoryFile = new File(fileName).getParentFile(); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created."); } } System.out.println("Creating " + fileName); final FileWriter writer = new FileWriter(fileName); try { writer.write(indexText); } finally { writer.close(); } }
From source file:doc.doclets.WorkbenchHelpDoclet.java
private static void _writeHtmlTOC(final String indexText) throws IOException { String fileBaseName = "passerelle.html"; String fileName = null;/*from ww w . ja v a 2s .co m*/ if (_outputDirectory != null) { fileName = _outputDirectory + File.separator + "html" + File.separator + fileBaseName; } else { fileName = fileBaseName; } // If necessary, create the directory. final File directoryFile = new File(fileName).getParentFile(); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created."); } } System.out.println("Creating " + fileName); final FileWriter writer = new FileWriter(fileName); try { writer.write(indexText); } finally { writer.close(); } }
From source file:doc.doclets.WorkbenchHelpDoclet.java
/** * Write the output to a file.//from w w w . j av a2 s . c om * * @param className The dot separated fully qualified classname, which is used to specify the directory and filename to which the documentation is written. * @param documentation The documentation that is written. * @exception IOException If there is a problem writing the documentation. */ private static void _writeDoc(final String className, final String documentation) throws IOException { String fileBaseName = className + ".html"; String fileName = null; if (_outputDirectory != null) { fileName = _outputDirectory + File.separator + "html" + File.separator + fileBaseName; } else { fileName = fileBaseName; } // If necessary, create the directory. final File directoryFile = new File(fileName).getParentFile(); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created."); } } System.out.println("Creating " + fileName); final FileWriter writer = new FileWriter(fileName); try { writer.write(documentation); } finally { writer.close(); } }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>/*from ww w . j av a 2s .com*/ * ? ? ? . * </p> * @param file * <code>File</code> * @param text * <code>String</code> */ public static void writeFile(File file, String text) { FileWriter writer = null; try { writer = new FileWriter(file); writer.write(text); } catch (Exception e) { log.error("Error creating File: " + file.getName() + ":" + e); return; } finally { try { writer.close(); } catch (Exception e) { } } }
From source file:org.apache.hadoop.gateway.SecureClusterTest.java
private static File setupJaasConf(File baseDir, String keyTabFile, String principal) throws IOException { File file = new File(baseDir, "jaas.conf"); if (!file.exists()) { file.createNewFile();/* ww w. j ava 2 s.com*/ } else { file.delete(); file.createNewFile(); } FileWriter writer = new FileWriter(file); String content = String.format("com.sun.security.jgss.initiate {\n" + "com.sun.security.auth.module.Krb5LoginModule required\n" + "renewTGT=true\n" + "doNotPrompt=true\n" + "useKeyTab=true\n" + "keyTab=\"%s\"\n" + "principal=\"%s\"\n" + "isInitiator=true\n" + "storeKey=true\n" + "useTicketCache=true\n" + "client=true;\n" + "};\n", keyTabFile, principal); writer.write(content); writer.close(); return file; }
From source file:de.julielab.jtbd.TokenizerApplication.java
/** * writes an ArrayList of Strings to a file * * @param lines//from w w w. java 2s . c om * the ArrayList * @param outFile */ static void writeFile(final ArrayList<String> lines, final File outFile) { try { final FileWriter fw = new FileWriter(outFile); for (int i = 0; i < lines.size(); i++) fw.write(lines.get(i) + "\n"); fw.close(); } catch (final Exception e) { System.err.println("ERR: error writing file: " + outFile.toString()); e.printStackTrace(); System.exit(-1); } }