Package java.io

Examples of java.io.FileWriter


   */
  public void testCommandLineSingleBib() throws Exception {

    // First check conversion from .bib to .xmp
    File tempBib = File.createTempFile("JabRef", ".bib");
    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(tempBib);
      fileWriter.write(t1BibtexString());
      fileWriter.close();

      ByteArrayOutputStream s = new ByteArrayOutputStream();
      PrintStream oldOut = System.out;
      System.setOut(new PrintStream(s));
      XMPUtil.main(new String[] { tempBib.getAbsolutePath() });
      System.setOut(oldOut);
      s.close();
      String xmp = s.toString();

      writeManually(pdfFile, xmp);

      List<BibtexEntry> l = XMPUtil.readXMP(pdfFile);
      assertEquals(1, l.size());
      assertEquals(t1BibtexEntry(), l.get(0));

    } finally {
      if (fileWriter != null)
        fileWriter.close();
      if (tempBib != null)
        tempBib.delete();
    }
  }
View Full Code Here


   *
   */
  public void testCommandLineByKey() throws Exception {

    File tempBib = File.createTempFile("JabRef", ".bib");
    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(tempBib);
      fileWriter.write(t1BibtexString());
      fileWriter.write(t2BibtexString());
      fileWriter.close();

      { // First try canh05
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        PrintStream oldOut = System.out;
        System.setOut(new PrintStream(s));
        XMPUtil.main(new String[] { "canh05",
            tempBib.getAbsolutePath(), pdfFile.getAbsolutePath() });
        System.setOut(oldOut);
        s.close();

        // PDF should be annotated:
        List<BibtexEntry> l = XMPUtil.readXMP(pdfFile);
        assertEquals(1, l.size());
        assertEquals(t1BibtexEntry(), l.get(0));
      }
      { // Now try OezbekC06
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        PrintStream oldOut = System.out;
        System.setOut(new PrintStream(s));
        XMPUtil.main(new String[] { "OezbekC06",
            tempBib.getAbsolutePath(), pdfFile.getAbsolutePath() });
        System.setOut(oldOut);
        s.close();
        // PDF should be annotated:
        List<BibtexEntry> l = XMPUtil.readXMP(pdfFile);
        assertEquals(1, l.size());
        assertEquals(t2BibtexEntry(), l.get(0));
      }
    } finally {
      if (fileWriter != null)
        fileWriter.close();

      if (tempBib != null)
        tempBib.delete();
    }
  }
View Full Code Here

   *
   */
  public void testCommandLineSeveral() throws Exception {

    File tempBib = File.createTempFile("JabRef", ".bib");
    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(tempBib);
      fileWriter.write(t1BibtexString());
      fileWriter.write(t3BibtexString());
      fileWriter.close();

      ByteArrayOutputStream s = new ByteArrayOutputStream();
      PrintStream oldOut = System.out;
      System.setOut(new PrintStream(s));
      XMPUtil.main(new String[] { tempBib.getAbsolutePath(),
          pdfFile.getAbsolutePath() });
      System.setOut(oldOut);
      s.close();

      List<BibtexEntry> l = XMPUtil.readXMP(pdfFile);

      assertEquals(2, l.size());

      BibtexEntry a = l.get(0);
      BibtexEntry b = l.get(1);

      if (a.getCiteKey().equals("Clarkson06")) {
        BibtexEntry tmp = a;
        a = b;
        b = tmp;
      }

      BibtexEntry t1 = t1BibtexEntry();
      BibtexEntry t3 = t3BibtexEntry();

      // Writing and reading will resolve strings!
      t3.setField("month", "July");

      assertEquals(t1, a);
      assertEquals(t3, b);

    } finally {
      if (fileWriter != null)
        fileWriter.close();

      if (tempBib != null)
        tempBib.delete();
    }
  }
View Full Code Here

                final File parent = this.reportFile.getParentFile();
                if (parent != null && !parent.exists())
                {
                    parent.mkdirs();
                }
                final FileWriter writer = new FileWriter(this.reportFile);
                writer.write(report.toString());
                writer.flush();
                writer.close();
            }
            catch (IOException exception)
            {
                throw new RuntimeException(exception);
            }
View Full Code Here

        File dir = buildDir(packageName);
        File fn = new File(dir , fileName);
        if (fn.exists() && !fn.delete()) {     
            throw new IOException(fn + ": Can't delete previous version");         
        }
        return new FileWriter(fn);
    }
View Full Code Here

    }
  }

  protected void write(File f){
    try {
      FileWriter fw=new FileWriter(f);
      fw.write(getText());
      fw.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

         // open the stream for writing again.
         final boolean append = false;
         count++;
         String tmpFilename = dumperFilename + format.format(count);
         nextChangeDate = startDate + (changeDumpFrequency*count);
         dumper = new FileWriter(tmpFilename, append);
      }
      catch (IOException ex) {
         ex.printStackTrace();
      }
   }
View Full Code Here

    // Parámetros:
    //             sPath       -> Ruta al archivo de salida
    //             oParameters -> Parámetros adicionales de creación
    //             (típicamente: font, color, etc)

    FileWriter oWriter = new FileWriter(sPath);
    Iterator oKeyIterator;
    Object oKey;
    Vector oContainers;
    int iContainers;

    // Escribir a capón los nodos del PageSet
    oWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    oWriter.write("<?xml-stylesheet type=\"text/xsl\"?>\n");
    oWriter.write("<?xml-stylesheet type=\"text/xsl\"?>\n");
    oWriter.write("<pageset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"pageset.xsd\" guid=\"" + Gadgets.generateUUID() + "\">\n");
    oWriter.write("  <microsite>" + this.guid() + "</microsite>\n");

    oKeyIterator = oParameters.keySet().iterator();
    while (oKeyIterator.hasNext()) {
      oKey = oKeyIterator.next();
      oWriter.write("  <" + oKey.toString() + ">" + oParameters.get(oKey).toString() + "</" + oKey.toString() + ">\n");
    } // wend()
    oKeyIterator = null;

    oWriter.write("  <pages>\n");

    oContainers = this.containers();
    iContainers = oContainers.size();

    for (int p=0; p<iContainers; p++) {
      oWriter.write("    <page guid=\">" + Gadgets.generateUUID() + "\">\n");
      oWriter.write("      <title>Pagina " + String.valueOf(p) + "</title>\n");
      oWriter.write("      <container>" + ((Container) oContainers.get(p)).guid() + "</container>\n");
      oWriter.write("      <blocks>\n");
      oWriter.write("      </blocks>\n");
      oWriter.write("    </page>\n");
    } // next(p)

    oWriter.write("  </pages>\n");
    oWriter.write("</pageset>\n");

    oWriter.close();
    oWriter = null;
  } // createPageSet()
View Full Code Here

                                        contents = contents.replaceAll(
                                                extensionPattern,
                                                newExtension);
                                    }
                                }
                                final FileWriter fileWriter = new FileWriter(newFile);
                                fileWriter.write(contents);
                                fileWriter.flush();
                            }
                        }
                    }
                }
            }
View Full Code Here

                                            contents.replaceAll(
                                                extensionPattern,
                                                newExtension);
                                    }
                                }
                                final FileWriter fileWriter = new FileWriter(newFile);
                                fileWriter.write(contents);
                                fileWriter.flush();
                                final File xmlZipFile = new File(buildDirectory, this.finalName + ".xml.zip");
                                this.writeModelArchive(
                                    xmlZipFile,
                                    newFile.toString());
                            }
View Full Code Here

TOP

Related Classes of java.io.FileWriter

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.