Пример #1
0
 private void getFileContent() throws KettleException {
   try {
     data.filecontent = getTextFileContent(data.file.toString(), meta.getEncoding());
   } catch (java.lang.OutOfMemoryError o) {
     logError(
         "There is no enaugh memory to load the content of the file ["
             + data.file.getName()
             + "]");
     throw new KettleException(o);
   } catch (Exception e) {
     throw new KettleException(e);
   }
 }
Пример #2
0
  private Object[] getOneRow() throws KettleException {
    if (!openNextFile()) {
      return null;
    }

    // Build an empty row based on the meta-data
    Object[] outputRowData = buildEmptyRow();

    try {
      // Create new row	or clone
      if (meta.getIsInFields())
        System.arraycopy(data.readrow, 0, outputRowData, 0, data.readrow.length);

      // Read fields...
      for (int i = 0; i < data.nrInputFields; i++) {
        // Get field
        LoadFileInputField loadFileInputField = meta.getInputFields()[i];

        String o = null;
        switch (loadFileInputField.getElementType()) {
          case LoadFileInputField.ELEMENT_TYPE_FILECONTENT:

            // DO Trimming!
            switch (loadFileInputField.getTrimType()) {
              case LoadFileInputField.TYPE_TRIM_LEFT:
                data.filecontent = Const.ltrim(data.filecontent);
                break;
              case LoadFileInputField.TYPE_TRIM_RIGHT:
                data.filecontent = Const.rtrim(data.filecontent);
                break;
              case LoadFileInputField.TYPE_TRIM_BOTH:
                data.filecontent = Const.trim(data.filecontent);
                break;
              default:
                break;
            }
            o = data.filecontent;
            break;
          case LoadFileInputField.ELEMENT_TYPE_FILESIZE:
            o = String.valueOf(data.fileSize);
            break;
          default:
            break;
        }

        int indexField = data.totalpreviousfields + i;
        // Do conversions
        //
        ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(indexField);
        ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(indexField);
        outputRowData[indexField] = targetValueMeta.convertData(sourceValueMeta, o);

        // Do we need to repeat this field if it is null?
        if (loadFileInputField.isRepeated()) {
          if (data.previousRow != null && o == null) {
            outputRowData[indexField] = data.previousRow[indexField];
          }
        }
      } // End of loop over fields...
      int rowIndex = data.totalpreviousfields + data.nrInputFields;

      // See if we need to add the filename to the row...
      if (meta.includeFilename()
          && meta.getFilenameField() != null
          && meta.getFilenameField().length() > 0) {
        outputRowData[rowIndex++] = data.filename;
      }

      // See if we need to add the row number to the row...
      if (meta.includeRowNumber()
          && meta.getRowNumberField() != null
          && meta.getRowNumberField().length() > 0) {
        outputRowData[rowIndex++] = new Long(data.rownr);
      }
      // Possibly add short filename...
      if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
        outputRowData[rowIndex++] = data.shortFilename;
      }
      // Add Extension
      if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
        outputRowData[rowIndex++] = data.extension;
      }
      // add path
      if (meta.getPathField() != null && meta.getPathField().length() > 0) {
        outputRowData[rowIndex++] = data.path;
      }

      // add Hidden
      if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
        outputRowData[rowIndex++] = new Boolean(data.hidden);
      }
      // Add modification date
      if (meta.getLastModificationDateField() != null
          && meta.getLastModificationDateField().length() > 0) {
        outputRowData[rowIndex++] = data.lastModificationDateTime;
      }
      // Add Uri
      if (meta.getUriField() != null && meta.getUriField().length() > 0) {
        outputRowData[rowIndex++] = data.uriName;
      }
      // Add RootUri
      if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
        outputRowData[rowIndex++] = data.rootUriName;
      }
      RowMetaInterface irow = getInputRowMeta();

      data.previousRow =
          irow == null ? outputRowData : (Object[]) irow.cloneRow(outputRowData); // copy it to make
      // surely the next step doesn't change it in between...

      incrementLinesInput();
      data.rownr++;

    } catch (Exception e) {
      throw new KettleException("Impossible de charger le fichier", e);
    }

    return outputRowData;
  }