Package java.io

Examples of java.io.FileWriter


  } // parse()

  // ----------------------------------------------------------

  public void createClassSource(String sPackage, String sSubClassName, String sFile) throws IOException{
    FileWriter oFile = new FileWriter(sFile);
    DataTransformation oDatT;
    Iterator oIter;
    LinkedList oList;
    Object oPKs;
    String sItem;

    oFile.write("package " + sPackage + ";\n");
    oFile.write("import java.util.Vector;\n");
    oFile.write("import java.util.LinkedList;\n");
    oFile.write("import java.util.ListIterator;\n");
    oFile.write("import java.util.HashMap;\n");
    oFile.write("import java.util.Iterator;\n");
    oFile.write("import com.knowgate.datacopy.DataRowSet;\n");
    oFile.write("import com.knowgate.datacopy.DataStruct;\n");
    oFile.write("import com.knowgate.datacopy.DataTransformation;\n");
    oFile.write("\n");

    oFile.write("public class " + sSubClassName + " extends DataStruct {\n");
    oFile.write("  public " + sSubClassName + "() {\n");
    oFile.write("    DataRowSet oRowSet;\n");
    oFile.write("    DataTransformation oTransForm;\n");
    oFile.write("    LinkedList oBefore;\n");
    oFile.write("    LinkedList oAfter;\n");
    oFile.write("    HashMap oMappings;\n");
    oFile.write("    HashMap oDefaults;\n");
    oFile.write("    HashMap oTransforms;\n\n");
    oFile.write("    InitStmts = new LinkedList();\n");
    oFile.write("    TermStmts = new LinkedList();\n");
    oFile.write("    oToPKs = new HashMap();\n");
    oFile.write("    oFromPKs = new HashMap();\n");
    oFile.write("    cTables = " + String.valueOf(DataRowSets.size()) + ";\n");
    oFile.write("\n");

    oIter = InitStmts.listIterator();
    while (oIter.hasNext())
      oFile.write("    InitStmts.addLast(\"" + oIter.next().toString() + "\");\n");
    oFile.write("\n");

    oIter = TermStmts.listIterator();
    while (oIter.hasNext())
      oFile.write("    TermStmts.addLast(\"" + oIter.next().toString() + "\");\n");
    oFile.write("\n");

    for (int c=0;c<cTables;c++) {
      oCurrRowSet  = getRowSet(c);

      oFile.write("    oRowSet = new DataRowSet(\"" + oCurrRowSet.OriginTable + "\",\"" + oCurrRowSet.TargetTable + "\",\"" + oCurrRowSet.JoinTables + "\",\"" + oCurrRowSet.WhereClause + "\",\"" + oCurrRowSet.EraseClause + "\");\n");
      oFile.write("    oRowSet.FieldList = \"" + oCurrRowSet.FieldList.trim() + "\";\n");
      oFile.write("    DataRowSets.add(oRowSet);\n");
      oFile.write("    oBefore = new LinkedList();\n");
      oFile.write("    oAfter = new LinkedList();\n");
      oFile.write("    oMappings = new HashMap();\n");
      oFile.write("    oDefaults = new HashMap();\n");
      oFile.write("    oTransforms = new HashMap();\n");

      oPKs = oFromPKs.get(oCurrRowSet.OriginTable);
      if (null!=oPKs)
        oFile.write("    oFromPKs.put(\"" + oCurrRowSet.OriginTable + "\",\"" + oPKs.toString() + "\");\n");
      oPKs = oToPKs.get(oCurrRowSet.TargetTable);
      if (null!=oPKs)
        oFile.write("    oToPKs.put(\"" + oCurrRowSet.TargetTable + "\",\"" + oPKs.toString() + "\");\n\n");

      oList = (LinkedList) Before.get(c);
      if (oList.size()>0) {
        oIter = oList.iterator();
        while (oIter.hasNext())
          oFile.write("    oBefore.addLast(\"" + oIter.next().toString() + "\");\n");
        oIter = null;
      } // fi (oList.size()>0)
      oList = null;
      oFile.write("    Before.add(oBefore);\n");

      oList = (LinkedList) After.get(c);
      if (oList.size()>0) {
        oIter = oList.iterator();
        while (oIter.hasNext())
          oFile.write("    oAfter.addLast(\"" + oIter.next().toString() + "\");\n");
        oIter = null;
      } // fi (oList.size()>0)
      oList = null;
      oFile.write("    After.add(oAfter);\n");

      try {
        oCurrMap = (HashMap) FieldMaps.get(c);
        oIter = oCurrMap.keySet().iterator();
        while (oIter.hasNext()) {
          sItem = (String) oIter.next();
          oFile.write("    oMappings.put(\"" + sItem + "\",\"" + oCurrMap.get(sItem).toString() + "\");\n");
        } // wend
      } catch (ArrayIndexOutOfBoundsException e) { }

      oFile.write("    FieldMaps.add(oMappings);\n");

      try {
        oFile.write("    Transformations.add(oTransforms);\n");
        oCurrTransform = (HashMap) Transformations.get(c);
        oIter = oCurrTransform.keySet().iterator();
        while (oIter.hasNext()) {
          sItem = oIter.next().toString();
          oDatT = (DataTransformation) oCurrTransform.get(sItem);
          oFile.write("    oTransForm = new DataTransformation(" + String.valueOf(oDatT.OperationCode) + "," +
                      "\"" + oDatT.OriginTable + "\",\"" + oDatT.OriginField + "\"," +
                      "\"" + oDatT.TargetTable + "\",\"" + oDatT.TargetField + "\"," +
                      (null==oDatT.ReferedTable ? "null" : "\"" + oDatT.ReferedTable + "\"") + "," +
                      (null==oDatT.ReferedField ? "null" : "\"" + oDatT.ReferedField + "\"") + "," +
                      (null==oDatT.IfNullValue  ? "null" : "\"" + oDatT.IfNullValue + "\"") + ");\n");
          oFile.write("    oTransforms.put(\"" + sItem + "\", oTransForm);\n");
          if (oDatT.OperationCode==DataTransformation.Operations.REFER) oFile.write("    seekReferal(oTransForm);\n");
        } // wend
      } catch (ArrayIndexOutOfBoundsException e) { }

      try {
        oCurrDef = (HashMap) FieldDefs.get(c);
        oIter = oCurrDef.keySet().iterator();
        while (oIter.hasNext()) {
          sItem = (String) oIter.next();
          oFile.write("    oMappings.put(\"" + sItem + "\",\"" + oCurrDef.get(sItem).toString() + "\");\n");
        } // wend
      } catch (ArrayIndexOutOfBoundsException e) { }

      oFile.write("    FieldDefs.add(oDefaults);\n");

      oFile.write("\n");
    // end for (c)

    oFile.write("  }\n}");

    oFile.close();
    oFile = null;
  } // createClassSource ()
View Full Code Here


    public void setUp() throws IOException {
        File resource = File.createTempFile("test", "resource");
        resource.deleteOnExit();
        resourceName = resource.getName();

        FileWriter writer = new FileWriter(resource);
        writer.write(RESOURCE_DATA);
        writer.write("\n");
        writer.close();

        URL[] urls = {resource.getParentFile().toURL()};
        ClassLoader loader = new URLClassLoader(urls);
        assertNotNull(loader.getResourceAsStream(resourceName));
        assertNull(ClassLoader.getSystemResourceAsStream(resourceName));
View Full Code Here

    FileOutputStream oOutStrm = null;
    FileInputStream oInStrm = null;
    BufferedInputStream oInBuff;
    BufferedOutputStream oOutBuff;
    // File with a description of all errors
    FileWriter oBadWrtr = null;
    // File with just the rows that failed to be inserted
    FileWriter oDiscardWrtr = null;
    // Intermediate buffer for SQL composition
    StringBuffer oSQL = new StringBuffer();
    StringBuffer oRow = new StringBuffer();

      if (DebugFile.trace) DebugFile.writeln("  Begin inserting data...");

      // ********************
      // Open data input file

    if (sCmd.equalsIgnoreCase("APPEND") || sCmd.equalsIgnoreCase("UPDATE") || sCmd.equalsIgnoreCase("APPENDUPDATE")) {
      try {
        if (DebugFile.trace) {
          DebugFile.writeln("  new FileInputStream("+sInFile+")");
          DebugFile.writeln("  input file length is "+String.valueOf(oInFile.length())+" bytes");
        }
        oInStrm = new FileInputStream(oInFile);
      } catch (FileNotFoundException fnfe) {
        try { oConn.close(); } catch (Exception ignore) {}
        throw new ImportExportException("File not found opening stream "+sInFile, fnfe);
      }
      // Java direct I/O performance sucks so use an intermediate buffer
      oInBuff = new BufferedInputStream(oInStrm);

      // **********************************
      // Open bad and discard file writters

      if (sBadFile!=null) {
        try {
          if (DebugFile.trace) DebugFile.writeln("  new FileWriter("+sBadFile+")");
          oBadWrtr = new FileWriter(sBadFile, false);
        }
        catch (FileNotFoundException neverthrown) {}
        catch (IOException ioe) {
          try { oInBuff.close(); } catch (Exception ignore) {}
          try { oInStrm.close(); } catch (Exception ignore) {}
          try { oConn.close(); } catch (Exception ignore) {}
          throw new ImportExportException("IOException "+ioe.getMessage(), ioe);
        }
      }
      if (sDiscardFile!=null) {
        try {
          if (DebugFile.trace) DebugFile.writeln("  new FileWriter("+sDiscardFile+")");
          oDiscardWrtr = new FileWriter(sDiscardFile, false);

        }
        catch (FileNotFoundException neverthrown) {}
        catch (IOException ioe) {
          try { oBadWrtr.close(); } catch (Exception ignore) {}
          try { oInBuff.close(); } catch (Exception ignore) {}
          try { oInStrm.close(); } catch (Exception ignore) {}
          try { oConn.close(); } catch (Exception ignore) {}
          throw new ImportExportException("IOException "+ioe.getMessage(), ioe);
        }
      }

      // *****************************************************************
      // If RECOVERABLE mode is enabled then set AutoCommit OFF else switch
      // AutoCommit ON and commit each row just after insertion

      try {
        oImplLoad.prepare(oConn, oColumns);
        if (bRecoverable)
          oConn.setAutoCommit(false);
        else
          oConn.setAutoCommit(true);
      } catch (Exception xcpt) {
        try { oBadWrtr.close(); } catch (Exception ignore) {}
        try { oInBuff.close(); } catch (Exception ignore) {}
        try { oInStrm.close(); } catch (Exception ignore) {}
        try { oImplLoad.close(); } catch (Exception ignore) {}
        try { oConn.close(); } catch (Exception ignore) {}
        throw new ImportExportException(xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
      }

    if (sEntity.equalsIgnoreCase("VCARDS")) {
        try {
      VCardParser oPrsr = new VCardParser();
      oPrsr.parse(oInBuff, sCharSet);
      VCardLoader oVCrdLoad = (VCardLoader) oImplLoad;
      for (HashMap<String,String> oVCard : oPrsr.vcards()) {
        oVCrdLoad.put(oVCard);
        try {
          oVCrdLoad.store(oConn, sWorkArea, iFlags);
              } catch (Exception xcpt) {
                iErrorCount++;
                if (DebugFile.trace) DebugFile.writeln("  "+xcpt.getClass().getName()+": at line "+String.valueOf(iLine)+" "+xcpt.getMessage());
                if (bRecoverable) {
                  if (DebugFile.trace) DebugFile.writeln("  Connection.rollback()");
                  try { oConn.rollback(); } catch (SQLException ignore) {}
                } // fi (bRecoverable)
                if (oBadWrtr!=null) {
                  oBadWrtr.write(xcpt.getClass().getName()+": at card "+oVCard.get("N")+" "+xcpt.getMessage()+"\r\n");
                } // fi
                if (oDiscardWrtr!=null) {
                  oDiscardWrtr.write(oVCard.get("N")+sRowDelim);
                } // fi
              } // catch
      } // next

            if (oInBuff!=null) { oInBuff.close(); }
            oInBuff=null;
            if (oInStrm!=null) { oInStrm.close(); }
            oInStrm=null;
            if (oBadWrtr!=null) { oBadWrtr.close(); oBadWrtr=null; }
            if (oDiscardWrtr!=null) { oDiscardWrtr.close(); oDiscardWrtr=null; }

            oImplLoad.close();
            if (bRecoverable) {
            if (0==iErrorCount)
              oConn.commit();
            else
              oConn.rollback();
            }

            if (DebugFile.trace) DebugFile.writeln("Connection.close()");
            oConn.close();
        } catch (Exception xcpt) {
             if (DebugFile.trace) DebugFile.writeln("  "+xcpt.getClass().getName()+" "+xcpt.getMessage());
             try { if (null!=oDiscardWrtr) oDiscardWrtr.close(); } catch (Exception ignore) {}
             try { if (null!=oBadWrtr) oBadWrtr.close(); } catch (Exception ignore) {}
             try { if (null!=oInBuff) oInBuff.close(); } catch (Exception ignore) {}
             try { if (null!=oInStrm) oInStrm.close(); } catch (Exception ignore) {}
             try { oImplLoad.close(); } catch (Exception ignore) {}
             try { if (bRecoverable) oConn.rollback(); } catch (Exception ignore) {}
             try { oConn.close(); } catch (Exception ignore) {}
             throw new ImportExportException(xcpt.getClass().getName() + " " + xcpt.getMessage());
        }
    } else {

        // *******************************************************
        // Check that all column names on input file are valid
        // and resolve column names to positions for faster access
 
        if (DebugFile.trace) DebugFile.writeln("Resolving column names to positions...");
        for (c=0; c<iColFmtsCount; c++) {
          DBColumn oClmn = oColumns.getColumn(c);
          if (oClmn.getSqlType()!=Types.NULL) {
            int cIndex = oImplLoad.getColumnIndex(oClmn.getName());
            if (-1==cIndex) {
              throw new ImportExportException("SQLException column "+oClmn.getName()+" not found at base table");
            } else {
              oClmn.setPosition(cIndex);
            }
          }
        } // next (c)
 
        // ******************************************
        // Read data input file and insert row by row
 
        if (DebugFile.trace) DebugFile.writeln("Begin read data from text file...");

    InputStreamReader oInRdr = null;
        try {
          // Use an stream reader for decoding bytes into the proper charset
          if (DebugFile.trace) DebugFile.writeln("  new InputStreamReader(BufferedInputStream,"+sCharSet+")");
          oInRdr = new InputStreamReader(oInBuff, sCharSet);
        } catch (java.io.UnsupportedEncodingException uee) {
          try { oInBuff.close(); } catch (Exception ignore) {}
          try { oInStrm.close(); } catch (Exception ignore) {}
          try { oConn.close(); } catch (Exception ignore) {}
          throw new ImportExportException("Unsupported Encoding "+sCharSet, uee);
        }

        try {         
          if (DebugFile.trace) {
            String sRowDelimChr = "", sColDelimChr = "";
            for (int d=0; d<sRowDelim.length(); d++) sRowDelimChr += "Chr("+String.valueOf((int)sRowDelim.charAt(d))+")";
            for (int d=0; d<sColDelim.length(); d++) sColDelimChr += "Chr("+String.valueOf((int)sColDelim.charAt(d))+")";
            DebugFile.writeln("  Read input stream with row delimiter "+sRowDelimChr+" and col delimiter "+sColDelimChr);
          }
          int nCharCount = 0;
          // Read input file by one character at a time
          while (((i=oInRdr.read())!=-1) && (iErrorCount<=iMaxErrors)) {
            nCharCount++;
            // Skip row delimiter, let r be the relative position inside the row delimiter
            // then skip as many characters readed at i as they match with row delimiter + offset r
            r=0;
            while (i==sRowDelim.charAt(r) && i!=-1) {
              r++;
              i=oInRdr.read();
              if (r==iRowDelimLen) break;
            } // wend
            // If r>0 then the row delimiter has been reached Or
            // If i==-1 then it is the last line, so insert the row
            if (r==iRowDelimLen || i==-1) {
              if (iLine>iSkip) {
                if (DebugFile.trace) DebugFile.writeln("  Processing line "+String.valueOf(iLine));
                if (bPreserveSpace)
                  sLine = oRow.toString();
                else
                  sLine = oRow.toString().trim();
                if (sLine.length()>0) {
                  if (sColDelim.length()==1)
                    aLine = Gadgets.split(sLine, sColDelim.charAt(0));
                  else
                    aLine = Gadgets.split(sLine, sColDelim);
                  // If current line does have the same number of columns as in the
                  // file definition then report an error or raise an exception
                  if (aLine.length!=iColFmtsCount) {
                    iErrorCount++;
                    if (DebugFile.trace) DebugFile.writeln("  Error: at line "+String.valueOf(iLine)+" has "+String.valueOf(aLine.length)+" columns but should have "+String.valueOf(iColFmtsCount));
                    if (bRecoverable) {
                      if (DebugFile.trace) DebugFile.writeln("  Connection.rollback()");
                      try { oConn.rollback(); } catch (SQLException ignore) {}
                    }
                    if (oBadWrtr!=null) {
                      oBadWrtr.write("Error: at line "+String.valueOf(iLine)+" has "+String.valueOf(aLine.length)+" columns but should have "+String.valueOf(iColFmtsCount)+"\r\n");
                      oBadWrtr.write(sLine+"\r\n");
                    }
                    if (oDiscardWrtr!=null) {
                      oDiscardWrtr.write(sLine+sRowDelim);
                    }
                  } else {
                    // Up to here a single line as been readed and is kept in aLines array
                    try {
                      oImplLoad.setAllColumnsToNull();
                      if (bAllCaps) {
                        for (c=0; c<iColFmtsCount; c++) {
                          oColFmt = oColumns.getColumn(c);
                          if (oColFmt.getSqlType()!=Types.NULL) {
                            String sColName = oColFmt.getName();
                            if (DebugFile.trace) DebugFile.writeln("  ImportLoader.put("+sColName+"("+String.valueOf(oColFmt.getPosition())+"),"+aLine[c]+")");
                            if (sColName.equalsIgnoreCase(DB.tx_email) ||
                              sColName.equalsIgnoreCase(DB.tx_email_alt) ||
                                sColName.equalsIgnoreCase(DB.tx_alt_email) ||
                                sColName.equalsIgnoreCase(DB.tx_main_email) ||
                                sColName.equalsIgnoreCase(DB.tx_comments) ||
                                sColName.equalsIgnoreCase(DB.tx_remarks) ||
                                sColName.equalsIgnoreCase(DB.tx_nickname) ||
                                sColName.equalsIgnoreCase(DB.tx_pwd) ||
                                sColName.equalsIgnoreCase(DB.tx_pwd_sign) ||
                                sColName.startsWith("url_") ||
                                sColName.startsWith("de_") ||
                                sColName.startsWith("gu_") ||
                                sColName.startsWith("id_") ||
                                sColName.startsWith("tp_") )
                              oImplLoad.put(oColFmt.getPosition(), oColFmt.convert(aLine[c]));
                            else
                              oImplLoad.put(oColFmt.getPosition(), oColFmt.convert(aLine[c].toUpperCase()));
                          } // fi (getSqlType()!=NULL)
                        } // next c)
                      } else {
                        for (c=0; c<iColFmtsCount; c++) {
                          oColFmt = oColumns.getColumn(c);
                          if (oColFmt.getSqlType()!=Types.NULL) {
                            if (DebugFile.trace) DebugFile.writeln("  ImportLoader.put("+oColFmt.getName()+"("+String.valueOf(oColFmt.getPosition())+"),"+aLine[c]+")");
                            oImplLoad.put(oColFmt.getPosition(), oColFmt.convert(aLine[c]));
                          } // fi (getSqlType()!=NULL)
                        } // next c)
                      } // fi (ALLCAPS)
                      if (null!=sCategory) oImplLoad.put("gu_category", sCategory);
                      if (null!=sGuList) oImplLoad.put("gu_list", sGuList);
                      oImplLoad.store(oConn, sWorkArea, iFlags);
                    } catch (NumberFormatException xcpt) {
                      iErrorCount++;
                      if (DebugFile.trace) DebugFile.writeln("  NumberFormatException: at line "+String.valueOf(iLine)+" "+xcpt.getMessage());
                      if (bRecoverable) {
                        if (DebugFile.trace) DebugFile.writeln("  Connection.rollback()");
                        try { oConn.rollback(); } catch (SQLException ignore) {}
                      } // fi (bRecoverable)
                      if (oBadWrtr!=null) {
                        oBadWrtr.write("NumberFormatException: at line "+String.valueOf(iLine)+" "+xcpt.getMessage()+"\r\n");
                        oBadWrtr.write(sLine+"\r\n");
                      } // fi
                      if (oDiscardWrtr!=null) {
                        oDiscardWrtr.write(sLine+sRowDelim);
                      } // fi
                    } catch (SQLException xcpt) {
                      iErrorCount++;
                      if (DebugFile.trace) DebugFile.writeln("  SQLException: at line "+String.valueOf(iLine)+" "+xcpt.getMessage());
                      if (bRecoverable) {
                        if (DebugFile.trace) DebugFile.writeln("  Connection.rollback()");
                        try { oConn.rollback(); } catch (SQLException ignore) {}
                      } // fi (bRecoverable)
                      if (oBadWrtr!=null) {
                        oBadWrtr.write("SQLException: at line "+String.valueOf(iLine)+" "+xcpt.getMessage()+"\r\n");
                        oBadWrtr.write(sLine+"\r\n");
                      } // fi
                      if (oDiscardWrtr!=null) {
                        oDiscardWrtr.write(sLine+sRowDelim);
                      } // fi
                    } // catch
                  } // fi (aLine.length!=iColFmtsCount)
                } // fi (sLine!="")
              } else {
         if (DebugFile.trace) DebugFile.writeln("  Skiping line "+String.valueOf(iLine));
              } // fi (iLine>iSkip)
              oRow.setLength(0);
              if (i!=-1) oRow.append((char)i);
              iLine++;
              if (-1==i) break;
            } else {
              oRow.append((char)i);
            }// fi (r==iRowDelimLen || i==-1)
          } // wend
        if (null!=oInRdr) oInRdr.close();

          if (DebugFile.trace) {
            DebugFile.writeln("End read data from text file. "+String.valueOf(nCharCount)+" characters readed with error count "+String.valueOf(iErrorCount));
          }

        if (oInBuff!=null) { oInBuff.close(); }
        oInBuff=null;
        if (oInStrm!=null) { oInStrm.close(); }
        oInStrm=null;
        if (oBadWrtr!=null) { oBadWrtr.close(); oBadWrtr=null; }
        if (oDiscardWrtr!=null) { oDiscardWrtr.close(); oDiscardWrtr=null; }

        oImplLoad.close();
        if (bRecoverable) {
          if (0==iErrorCount)
            oConn.commit();
          else
            oConn.rollback();
        }

        if (DebugFile.trace) DebugFile.writeln("Connection.close()");
        oConn.close();
      } catch (SQLException xcpt) {
        if (DebugFile.trace) DebugFile.writeln("  "+xcpt.getClass().getName()+": at row "+String.valueOf(r)+" "+xcpt.getMessage());
        try { if (null!=oDiscardWrtr) oDiscardWrtr.close(); } catch (Exception ignore) {}
        try { if (null!=oBadWrtr) oBadWrtr.close(); } catch (Exception ignore) {}
        try { if (null!=oInBuff) oInBuff.close(); } catch (Exception ignore) {}
        try { if (null!=oInStrm) oInStrm.close(); } catch (Exception ignore) {}
        try { oImplLoad.close(); } catch (Exception ignore) {}
        try { if (bRecoverable) oConn.rollback(); } catch (Exception ignore) {}
        try { oConn.close(); } catch (Exception ignore) {}
        throw new ImportExportException(xcpt.getClass().getName() + " " + xcpt.getMessage() + " at row " + String.valueOf(r));
      }
      catch (IOException xcpt) {
             if (DebugFile.trace) DebugFile.writeln("  "+xcpt.getClass().getName()+": at row "+String.valueOf(r)+" "+xcpt.getMessage());
             try { if (null!=oDiscardWrtr) oDiscardWrtr.close(); } catch (Exception ignore) {}
             try { if (null!=oBadWrtr) oBadWrtr.close(); } catch (Exception ignore) {}
             try { if (null!=oInBuff) oInBuff.close(); } catch (Exception ignore) {}
             try { if (null!=oInStrm) oInStrm.close(); } catch (Exception ignore) {}
             try { oImplLoad.close(); } catch (Exception ignore) {}
             try { if (bRecoverable) oConn.rollback(); } catch (Exception ignore) {}
             try { oConn.close(); } catch (Exception ignore) {}
             throw new ImportExportException(xcpt.getClass().getName() + " " + xcpt.getMessage() + " at row " + String.valueOf(r));
      }
      catch (java.text.ParseException xcpt) {
            if (DebugFile.trace) DebugFile.writeln("  "+xcpt.getClass().getName()+": at row "+String.valueOf(r)+" "+xcpt.getMessage());
            try { if (null!=oDiscardWrtr) oDiscardWrtr.close(); } catch (Exception ignore) {}
            try { if (null!=oBadWrtr) oBadWrtr.close(); } catch (Exception ignore) {}
            try { if (null!=oInBuff) oInBuff.close(); } catch (Exception ignore) {}
            try { if (null!=oInStrm) oInStrm.close(); } catch (Exception ignore) {}
            try { oImplLoad.close(); } catch (Exception ignore) {}
            try { if (bRecoverable) oConn.rollback(); } catch (Exception ignore) {}
View Full Code Here

                    prop.put("status_url", url);
                    return prop;
                }
                try {
                    final File skinFile = new File(skinPath, url.substring(url.lastIndexOf('/'), url.length()));
                    final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(skinFile)));

                    while (it.hasNext()) {
                        bw.write(it.next() + "\n");
                    }
                   
View Full Code Here

        MultipartFormDataRequest req = new MultipartFormDataRequest("http://localhost:" + server.getLocalPort()+ "/");
       
        String name1 = "file4k";
        File file1 = File.createTempFile("test", "tmp");
        FileWriter fw = new FileWriter(file1);
        fw.write("0123456789");
        fw.close();
       
       
        String name2 = "file40k";
        File file2 = QAUtil.createTestfile_40k();
       
View Full Code Here

     */
    public void write()
        throws Exception
    {
        final File projectFile = this.getFile(".project");
        final FileWriter fileWriter = new FileWriter(projectFile);
        final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);
        writer.startElement("projectDescription");
        writer.startElement("name");
        writer.writeText(this.project.getArtifactId());
        writer.endElement();
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

        final String merge)
        throws Exception
    {
        final String rootDirectory = ResourceUtils.normalizePath(this.project.getBasedir().toString());
        final File classpathFile = new File(rootDirectory, ".classpath");
        final FileWriter fileWriter = new FileWriter(classpathFile);
        final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);

        writer.startElement("classpath");

        final Set projectArtifactIds = new LinkedHashSet();
View Full Code Here

                    prop.put("status_url", url);
                    return prop;
                }
                try {
                    final File langFile = new File(langPath, url.substring(url.lastIndexOf('/'), url.length()));
                    final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(langFile)));

                    while (it.hasNext()) {
                        bw.write(it.next() + "\n");
                    }
                    bw.close();
View Full Code Here

    try{

      // Now write to string and view as file.
      //System.out.println(iCal.getVCalendar());
     
      BufferedWriter out = new BufferedWriter(new FileWriter(args[1]));
          out.write(iCal.getVCalendar());
          out.close();
     
    }
    catch (Exception e)
View Full Code Here

TOP

Related Classes of java.io.FileWriter

Copyright © 2018 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.