Package org.jitterbit.plugin.sdk

Examples of org.jitterbit.plugin.sdk.OutputFiles


    if ( dataElements.contains("OutputExtension", DataType.STRING) ) {
      outputExtension = dataElements.get("OutputExtension", DataType.STRING).getValueAsString();
    }
   
    InputFiles inputFiles = input.getInputFiles();
    OutputFiles outputFiles = output.getOutputFiles();
    for( InputFile inputFile : inputFiles.getFiles() ) {
      File file = inputFile.getFile();
      CommandArgs commandArg = RunCommand.run(command, arg, file);
      if ( commandArg.hasOutputFileInArgument() ) {
        if ( outputExtension != null ) {
          // The output file has a special extension.
          String outFileName = commandArg.getOutputFile().getCanonicalPath() + outputExtension;
          outputFiles.add(new File(outFileName), inputFile);
        }
        else {
          outputFiles.add(commandArg.getOutputFile(), inputFile);
        }
      }
      else {
        if ( outputExtension != null ) {
          String inFileName = commandArg.getInputFile().getCanonicalPath() + outputExtension;
          outputFiles.add(new File(inFileName), inputFile);
        }
      }
    }
    return PluginResult.SUCCESS;
  }
View Full Code Here


          int iFile = 1;
          final BufferedReader br = new BufferedReader(new FileReader(input_file));
      File output_file = new File(getOutputFileName(input_file, iFile));
      BufferedWriter bw = new BufferedWriter(new FileWriter(output_file));
          try {
                final OutputFiles outputFiles = output.getOutputFiles();
            int iRecords = 0;
            String line = null;
            while (( line = br.readLine()) != null) {
              if ( line.isEmpty() ) {
                // Ignore empty lines.
                continue;
              }
             
              if ( line.startsWith(header_segment) ) {
                // New record
                ++iRecords;
                  if (iRecords > records_per_file ) {
                    // Enough records found, close the old file and open a new.
                    ++iFile;
                    iRecords = 1;
                    closeIgnoreException(bw);
                    bw = null;
                   
                    outputFiles.add(output_file, plugin_input_file);
                    output_file = new File(getOutputFileName(input_file, iFile));
                    bw = new BufferedWriter(new FileWriter(output_file));
                  }
              }
              bw.write(line);
              bw.newLine();
            }
        outputFiles.add(output_file, plugin_input_file);
          }
          finally {
            closeIgnoreException(br);
            closeIgnoreException(bw);
          }
View Full Code Here

        }
        return ret;
    }

    private void getResultData(Properties result, PipelinePluginContext context, PipelinePluginOutput output) {
      OutputFiles outputFiles = output.getOutputFiles();
      DataElements dataElements = context.getDataElements();
      String baseDir = result.getProperty(POP3Client.BASE_DIR_PROPERTY, "");
      int nAttachments = 0;
        for (String key : result.stringPropertyNames()) {
            if (isFileAttachment(key)) {
                String fileName = result.getProperty(key);
                outputFiles.add(new File(baseDir, fileName));
                dataElements.add(DataElementFactory.newDataElement(key, DataType.STRING, fileName));
                ++nAttachments;
            } else if (isOutputData(key)) {
                dataElements.add(DataElementFactory.newDataElement(key, DataType.STRING, result.getProperty(key)));
            }
View Full Code Here

       
//        System.out.println("Number of segment read:"+iRecords);
       
        iRecords = 0;
        int iFile = 1;
            OutputFiles outputFiles = output.getOutputFiles();
        File output_file = new File(getOutputFileName(input_file, iFile));
        FileOutputStream out = new FileOutputStream(output_file);
        try {
          for(List<Segment> list : map.values()){
            for(Segment s : list){
              s.write(out, raf);
              ++iRecords;
            }
            if(iRecords>=records_per_file){
  //            System.out.println("write output file: "+output_file+", number of segment written:"+iRecords);
              out.close();
              out = null;
              outputFiles.add(output_file);
             
              // Start the new file
              iRecords=0;
              ++iFile;
              output_file = new File(getOutputFileName(input_file, iFile));
              out = new FileOutputStream(output_file);
            }
          }
        }
        finally {
          if(out!=null) {
            if(iRecords>0) {
              // Only add the last file if it has any entries in it.
              outputFiles.add(output_file);
            }
            out.close();
          }
        }
       
View Full Code Here

    @Override
    public final PluginResult run(PipelinePluginInput input,
                                  PipelinePluginOutput output,
                                  PipelinePluginContext context) throws Exception {
        InputFiles inputFiles = input.getInputFiles();
        OutputFiles outputFiles = output.getOutputFiles();
        InputFileReader reader = new InputFileReader();
        OutputFileWriter writer = new OutputFileWriter();
        for (InputFile file : inputFiles.getFiles()) {
            getDefaultLogger(context).fine("Now handling the file " + file.getFile());
            String content = reader.read(file);
            String newContent = content.replaceAll(m_regex, m_replacement);
            if (content == newContent) {
                getDefaultLogger(context).fine("The file did not change.");
                outputFiles.add(file.getFile(), file);
            }
            else {
                getDefaultLogger(context).fine("A new file was generated.");
                OutputFile outputFile = createOutputFile(file, newContent, writer);
                outputFiles.add(outputFile);
            }
        }
        getDefaultLogger(context).fine("These are the output files:");
        StringBuilder sb = new StringBuilder();
        for (OutputFile out : output.getOutputFiles().getFiles()) {
View Full Code Here

    @Override
    public final PluginResult run(PipelinePluginInput input,
                                  PipelinePluginOutput output,
                                  PipelinePluginContext context) throws Exception {
        InputFiles inputFiles = input.getInputFiles();
        OutputFiles outputFiles = output.getOutputFiles();
        for (InputFile inputFile : inputFiles.getFiles()) {
            OutputFile outputFile = handle(inputFile);
            outputFiles.add(outputFile);
        }
        return PluginResult.SUCCESS;
    }
View Full Code Here

        }
        if ( segmentSet.isEmpty() ) {
          throw new PipelinePluginException("No segments were defined. Segment variable was '" + segments + ",");
        }
       
        OutputFiles outputFiles = output.getOutputFiles();
       
        for (InputFile plugin_input_file : files.getFiles()) {
          final File input_file = plugin_input_file.getFile();
          final File output_file = new File( input_file.getCanonicalPath() + "-line-break-plugin" );
          BufferedReader br = null;
          BufferedWriter bw = null;
          try {
            br = new BufferedReader(new FileReader(input_file));
            bw = new BufferedWriter(new FileWriter(output_file));
            String line = null;
            StringBuilder current_line = new StringBuilder();
            while (( line = br.readLine()) != null) {
              if ( line.isEmpty() ) {
                // Ignore empty lines.
                continue;
              }

              // Find the segment identifier
              int ipos = line.indexOf(separator);
              String seg;
              if ( ipos == -1 ) {
                seg = line;
              }
              else if ( ipos == 0 ) {
                seg = "";
              }
              else {
                seg = line.substring(0, ipos);
              }

              if (segmentSet.contains(seg) ) {
                // A new segment is found so we can write out the last line and start a new.
                if ( current_line.length() > 0 ) {
                    bw.write(current_line.toString());
                    bw.newLine();
                }
                current_line = new StringBuilder(line);
              }
              else {
                // The line does not start with a segment identifier so we need to skip the line break.
                current_line.append(line);
              }
            }
            if ( current_line.length() > 0 ) {
              bw.write(current_line.toString());
              bw.newLine();
            }
          }
          finally {
            closeIgnoreException(br);
            closeIgnoreException(bw);
          }
          outputFiles.add(output_file, plugin_input_file);
        }
       
        return PluginResult.SUCCESS;
    }
View Full Code Here

TOP

Related Classes of org.jitterbit.plugin.sdk.OutputFiles

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.