Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

In this page you can find the example usage for java.io FileWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:io.liveoak.filesystem.aggregating.HTTPAggregatingFilesystemResourceTest.java

public void setupNoOptional() {
    File dataDir = new File(projectRoot, "aggr");

    dataDir.mkdirs();/*from  ww  w  .  java 2 s  . co m*/

    // create some files in there
    try {
        FileWriter out = new FileWriter(new File(dataDir, "aggregate.js.aggr"));
        out.write("require first.js\n");
        out.write("require second.js\n");
        out.write("optional third.js\n");
        out.close();

        out = new FileWriter(new File(dataDir, "first.js"));
        out.write("// first.js\n");
        out.close();

        out = new FileWriter(new File(dataDir, "second.js"));
        out.write("// second.js\n");
        out.close();
    } catch (IOException e) {
        throw new RuntimeException("Failed to create a test file: ", e);
    }
}

From source file:de.uzk.hki.da.grid.IrodsGridFacadeTest.java

/**
 * Put file already exists with not applicable checksum.
 *
 * @throws Exception the exception/*from  w w w  .jav  a2  s . com*/
 * @author Jens Peters
 * @author Daniel M. de Oliveira
 */
@Test
public void putFileAlreadyExistsWithNotApplicableChecksum() throws Exception {

    if (!new File(irodsDir + "/aip/123456").exists())
        new File(irodsDir + "/aip/123456").mkdirs();
    File dis = new File(irodsDir + "/aip/123456/urn.tar");
    FileWriter writer = new FileWriter(dis, false);
    writer.write("Hallo Wie gehtsddfd?");
    writer.close();

    when(isc.executeRule(anyString(), anyString())).thenReturn("1") // -> replication solely on cache
            .thenReturn("1");
    when(isc.fileExists(anyString())).thenReturn(true);

    // assertEquals(false,ig.put(temp, "aip/123456/urn.tar"));
    assertEquals(true, temp.exists());
    assertEquals(true, ig.put(temp, "123456/urn.tar", sp, null));
    assertEquals(true, new File(irodsDir + "/aip/123456/urn.tar").exists());
}

From source file:mobi.jenkinsci.server.core.services.ImageRequestCommandTest.java

private File createImageFile() throws IOException {
    tmpFile = File.createTempFile(TMP_PREFIX, IMAGE_NAME_FROM_FILESYSTEM);
    final FileWriter out = new FileWriter(tmpFile);
    out.write(IMAGE_TEMP_FILE_CONTENT);
    out.close();/* w  ww.  j  a v a2  s. co  m*/
    return tmpFile;
}

From source file:io.liveoak.filesystem.aggregating.HTTPAggregatingFilesystemResourceTest.java

public void setupWithOptional() {
    File dataDir = new File(projectRoot, "aggr");

    dataDir.mkdirs();/*from   w w w  .j  a  va2  s  . co m*/

    // create some files in there
    try {
        FileWriter out = new FileWriter(new File(dataDir, "aggregate.js.aggr"));
        out.write("require first.js\n");
        out.write("require second.js\n");
        out.write("optional third.js\n");
        out.close();

        out = new FileWriter(new File(dataDir, "first.js"));
        out.write("// first.js\n");
        out.close();

        out = new FileWriter(new File(dataDir, "second.js"));
        out.write("// second.js\n");
        out.close();

        out = new FileWriter(new File(dataDir, "third.js"));
        out.write("// third.js\n");
        out.close();
    } catch (IOException e) {
        throw new RuntimeException("Failed to create a test file: ", e);
    }
}

From source file:AIR.ResourceBundler.Console.ResourcesBuilder.java

private void processParentResource(FileSet fileSet) throws Exception {
    String outputFile = Path.combine(_parentFolder, fileSet.getOutput());
    outputFile = outputFile.replace('/', File.separatorChar);
    File outputFolder = new File(outputFile).getParentFile();

    // make sure output folder exists
    if (!outputFolder.exists()) {
        FileUtils.forceMkdir(outputFolder);
    }/*from   ww w .  j  av a2  s.  co m*/

    File output = new File(outputFile);
    output.createNewFile();

    FileWriter sw = new FileWriter(output);

    sw.write("/*\n");
    sw.write(String.format("Copyright (c) %s, American Institutes for Research. All rights reserved.\n",
            DateTime.getNow().getYear()));
    sw.write(String.format("GENERATED: %s\n", DateTime.getNow().toString()));
    // TODO Shajib: In .net code Environment.MachineName used
    int machineHash = HttpContext.getCurrentContext().getServer().hashCode();
    String machineID = Integer.toString(machineHash);
    sw.write(String.format("MACHINE: %s\n", machineID));
    sw.write("*/\n");
    sw.write("\n");

    Iterator<FileSetInput> it = _resources.getFileInputs(fileSet.getName());
    FileSetInput file = null;

    for (; it.hasNext();) {
        file = it.next();
        writeFileInput(sw, file);
    }
}

From source file:de.uzk.hki.da.grid.IrodsGridFacadeTest.java

/**
 * Sets the up./*from  w  w  w.j a  va 2  s.c o m*/
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {

    isc = mock(IrodsSystemConnector.class);
    ig = new IrodsGridFacade();
    ig.setIrodsSystemConnector(isc);

    when(isc.computeChecksum(anyString())).thenReturn("abc");
    when(isc.isConnected()).thenReturn(true);

    sp = new StoragePolicy();
    sp.setWorkingResource("cacheresc");
    sp.setGridCacheAreaRootPath(Path.make(irodsDir).toString());
    sp.setWorkAreaRootPath(Path.make(forkDir).toString());
    sp.setReplDestinations("lvr");

    when(isc.getZone()).thenReturn("zone");
    new File(irodsDir).mkdir();
    new File(forkDir).mkdir();
    temp = new File(forkDir + "urn.tar");
    FileWriter writer = new FileWriter(temp, false);
    writer.write("Hallo Wie gehts?");
    writer.close();
}

From source file:com.bbn.c2s2.pint.testdata.chart.ScatterPlot.java

public void toCsvFile(String fileName) throws IOException {
    FileWriter fw = new FileWriter(fileName);
    for (int i = 0; i < data[0].length; i++) {
        String out = data[0][i] + "," + data[1][i];
        fw.write(out + '\n');
    }// ww w . j  ava2  s.c om
    fw.close();
}

From source file:forumbox.PostingnewpostServlet.java

public void filewrite(String url, String username, String title, String description,
        HttpServletResponse response, String id) throws IOException {

    count++;//from ww  w .j ava2 s  . com
    /*   BufferedWriter out ;
       out = new BufferedWriter(new FileWriter(url,true));
       out.write(count+"/"+array[0]+"/"+array[1]+"/"+array[2]+";");
       out.close();
               
               
      }catch (Exception e) {
    System.out.println("Error: " + e.getMessage());
      } */

    JSONObject post = new JSONObject();
    JSONArray comments = new JSONArray();
    JSONArray toapprove = new JSONArray();
    JSONParser parser = new JSONParser();
    JSONObject list = null;

    post.put("title", title);
    post.put("description", description);
    post.put("id", id);
    post.put("username", username);
    //  post.put("comments",comments);
    //  post.put("toapprove",toapprove);

    try {

        Object obj = parser.parse(new FileReader(url + "list.json"));
        list = (JSONObject) obj;

        JSONArray msg = (JSONArray) list.get("list");
        msg.add(id);

        list.remove("list");
        list.put("list", msg);

    } catch (Exception e) {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("Adding new ID is unsuccessful");
        out.println(e);
        out.println("......................");
    }

    try {

        File file = new File(url + id + ".json");
        file.createNewFile();
        BufferedWriter out;
        out = new BufferedWriter(new FileWriter(file));
        out.write(post.toJSONString());
        out.close();

        File fileList = new File(url + "list.json");
        //  fileList.createNewFile();
        // BufferedWriter outin ;
        //  outin = new BufferedWriter(new FileWriter(fileList));
        // outin.write(post.toJSONString());
        FileWriter listwrite = new FileWriter(fileList);
        listwrite.write(list.toJSONString());
        listwrite.flush();
        listwrite.close();
        //outin.close();

    } catch (IOException e) {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("adding new post is unsuccessful");
        out.println(e);
        out.println("......................");
    }

}

From source file:net.blogracy.controller.ActivitiesController.java

public void addFeedEntry(String id, String text, File attachment) {
    try {/*  w w w. j a  v  a  2 s.co  m*/
        String hash = sharing.hash(text);
        File textFile = new File(CACHE_FOLDER + File.separator + hash + ".txt");

        FileWriter w = new FileWriter(textFile);
        w.write(text);
        w.close();

        String textUri = sharing.seed(textFile);
        String attachmentUri = null;
        if (attachment != null) {
            attachmentUri = sharing.seed(attachment);
        }

        final List<ActivityEntry> feed = getFeed(id);
        final ActivityEntry entry = new ActivityEntryImpl();
        entry.setVerb("post");
        entry.setUrl(textUri);
        entry.setPublished(ISO_DATE_FORMAT.format(new Date()));
        entry.setContent(text);
        if (attachment != null) {
            ActivityObject enclosure = new ActivityObjectImpl();
            enclosure.setUrl(attachmentUri);
            entry.setObject(enclosure);
        }
        feed.add(0, entry);
        String feedUri = seedActivityStream(id, feed);
        DistributedHashTable.getSingleton().store(id, feedUri, entry.getPublished());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.igor_kudryashov.utils.notes.NotesTempFile.java

/**
 * Returns a temporary file and stores it name in the store ~ notetmp.reg
 * //from  w  w  w  . j a  v a 2 s.c  o  m
 * @param postfix
 *            - postfix of temporary filename.
 * @return the temporary file.
 */
public File getTempFile(String postfix) {
    File file = null;
    String p = postfix;
    try {
        if (p == null) {
            p = ".tmp";
        } else {
            if (!p.startsWith(".")) {
                p = "." + p;
            }
        }
        file = File.createTempFile("~$0", p, new File(tempFolder));
        // add filename to store
        File storeFile = new File(tempFolder + File.separator + NOTES_TMP_FILENAME);
        String filename = file.getName();
        String fixfilename = StringUtils.rightPad(filename, 257, '\0');
        FileWriter fw = new FileWriter(storeFile, true);
        fw.write(fixfilename);
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}