Search in sources :

Example 1 with IFSFileInputStream

use of com.ibm.as400.access.IFSFileInputStream in project IBMiProgTool by vzupka.

the class DisplayFile method displayIfsFile.

/**
 * Display contents of the IFS file using its CCSID attribute
 *
 * @param remoteServer
 * @param ifsFilePathString
 */
protected void displayIfsFile(AS400 remoteServer, String ifsFilePathString) {
    this.setTitle("Display IFS file  '" + ifsFilePathString + "'");
    // The user can correct the parameter "IBMi CCSID" and try again.
    try {
        IFSFile ifsFile = new IFSFile(remoteServer, ifsFilePathString);
        int attributeCCSID = ifsFile.getCCSID();
        characterSetLabel.setText("CCSID " + attributeCCSID + " was used for display.");
        byte[] inputBuffer = new byte[100000];
        byte[] workBuffer = new byte[100000];
        try (IFSFileInputStream inputStream = new IFSFileInputStream(remoteServer, ifsFilePathString)) {
            int bytesRead = inputStream.read(inputBuffer);
            while (bytesRead != -1) {
                for (int idx = 0; idx < bytesRead; idx++) {
                    // Copy input byte to output byte
                    workBuffer[idx] = inputBuffer[idx];
                }
                // Copy the printable part of the work array to a new buffer that will be written out.
                byte[] bufferToWrite = new byte[bytesRead];
                // Copy bytes from the work buffer to the new buffer
                for (int indx = 0; indx < bytesRead; indx++) {
                    bufferToWrite[indx] = workBuffer[indx];
                }
                // Create object for conversion from bytes to characters
                AS400Text textConverter = new AS400Text(bytesRead, attributeCCSID, remoteServer);
                // Convert byte array buffer to text line
                String textLine = (String) textConverter.toObject(bufferToWrite);
                // Append the line to text area
                textArea.append(textLine + NEW_LINE);
                // Read next input buffer
                bytesRead = inputStream.read(inputBuffer);
            }
            // Set scroll bar to top
            textArea.setCaretPosition(0);
            // Display the window.
            setVisible(true);
            row = "Info: IFS file  " + ifsFilePathString + "  has CCSID  " + attributeCCSID + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages(nodes);
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: " + exc.toString();
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(nodes);
    }
    // Remove message scroll listener (cancel scrolling to the last message)
    mainWindow.scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(mainWindow.messageScrollPaneAdjustmentListenerMax);
}
Also used : AS400Text(com.ibm.as400.access.AS400Text) Point(java.awt.Point) PatternSyntaxException(java.util.regex.PatternSyntaxException) BadLocationException(javax.swing.text.BadLocationException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream)

Example 2 with IFSFileInputStream

use of com.ibm.as400.access.IFSFileInputStream in project IBMiProgTool by vzupka.

the class EditFile method displayIfsFile.

/**
 * Display contents of the IFS file using its CCSID attribute.
 */
protected void displayIfsFile() {
    this.setTitle("Edit IFS file  '" + filePathString + "'");
    // Correct the parameter "IBMi CCSID".
    try {
        IFSFile ifsFile = new IFSFile(remoteServer, filePathString);
        ccsidAttribute = ifsFile.getCCSID();
        characterSetLabel.setText("CCSID " + ccsidAttribute + " was used for display.");
        byte[] inputBuffer = new byte[100000];
        byte[] workBuffer = new byte[100000];
        textArea.setText("");
        try (IFSFileInputStream inputStream = new IFSFileInputStream(remoteServer, filePathString)) {
            int bytesRead = inputStream.read(inputBuffer);
            while (bytesRead != -1) {
                for (int idx = 0; idx < bytesRead; idx++) {
                    // Copy input byte to output byte
                    workBuffer[idx] = inputBuffer[idx];
                }
                // Copy the printable part of the work array
                // to a new buffer that will be written out.
                byte[] bufferToWrite = new byte[bytesRead];
                // Copy bytes from the work buffer to the new buffer
                for (int indx = 0; indx < bytesRead; indx++) {
                    bufferToWrite[indx] = workBuffer[indx];
                }
                // Create object for conversion from bytes to characters
                AS400Text textConverter = new AS400Text(bytesRead, ccsidAttribute, remoteServer);
                // Convert byte array buffer to text line
                String textLine = (String) textConverter.toObject(bufferToWrite);
                // Append the line to text area
                textArea.append(textLine + NEW_LINE);
                // Read next input buffer
                bytesRead = inputStream.read(inputBuffer);
            }
        }
    } catch (Exception exc) {
        isError = true;
        row = "Error in displaying IFS file: " + exc.toString();
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(nodes);
    }
    // Remove message scroll listener (cancel scrolling to the last message)
    mainWindow.scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(mainWindow.messageScrollPaneAdjustmentListenerMax);
}
Also used : AS400Text(com.ibm.as400.access.AS400Text) Point(java.awt.Point) CannotUndoException(javax.swing.undo.CannotUndoException) CannotRedoException(javax.swing.undo.CannotRedoException) BadLocationException(javax.swing.text.BadLocationException) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream)

Example 3 with IFSFileInputStream

use of com.ibm.as400.access.IFSFileInputStream in project IBMiProgTool by vzupka.

the class Copy_IBMi_IBMi method copyToIfsFile.

/**
 * Copy IFS file or Source member or Save file to an IFS file; If the target
 * IFS file does not exist, one is created.
 *
 * @param targetPathString
 * @param sourcePathString
 * @param fromWalk
 * @return
 */
protected String copyToIfsFile(String sourcePathString, String targetPathString, boolean fromWalk) {
    if (targetPathString.equals(sourcePathString)) {
        return "ERROR";
    }
    // Path to input IFS file
    inputDirFile = new IFSFile(remoteServer, sourcePathString);
    // Path to output IFS file
    outputDirFile = new IFSFile(remoteServer, targetPathString);
    try {
        // ---------------
        if (sourcePathString.startsWith("/QSYS.LIB/")) {
            extractNamesFromIfsPath(sourcePathString);
            if (sourcePathString.endsWith(".FILE") && inputDirFile.isSourcePhysicalFile()) {
                if (targetPathString.endsWith(".savf")) {
                    row = "Error: Source file  " + libraryName + "/" + fileName + "  cannot be copied to IFS file  " + targetPathString + "  ending with .savf.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "ERROR";
                }
                msgText = copyFromSourceFile(remoteServer, sourcePathString, targetPathString);
                if (msgText.isEmpty()) {
                    row = "Comp: Source file  " + libraryName + "/" + fileName + "  was copied to IFS file  " + targetPathString + ".";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "";
                } else {
                    row = "Comp File: Source file  " + libraryName + "/" + fileName + "  was NOT copied to IFS file.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "ERROR";
                }
            }
            if (sourcePathString.endsWith(".MBR")) {
                if (targetPathString.endsWith(".savf")) {
                    row = "Error: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  cannot be copied to IFS file  " + targetPathString + "  ending with .savf.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "ERROR";
                }
                msgText = copyFromSourceMember(remoteServer, sourcePathString, targetPathString);
                if (msgText.isEmpty()) {
                    row = "Comp: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  was copied to IFS file  " + targetPathString + ".";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "";
                } else {
                    row = "Comp File: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  was NOT copied to IFS file.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "ERROR";
                }
            } else // ---------
            if (inputDirFile.toString().contains(".LIB") && inputDirFile.toString().endsWith(".SAVF")) {
                msgText = copyFromSaveFile(remoteServer, sourcePathString, targetPathString);
                return msgText;
            }
        } else {
            if (outputDirFile.isDirectory()) {
                // When IFS directory, add source file name
                // ------------------
                // IFS file path string = target IFS directory + source IFS file
                // name
                targetPathString = sourcePathStringPrefix + "/" + inputDirFile.getName();
                outputDirFile = new IFSFile(remoteServer, targetPathString);
            }
            // =======================================
            try {
                byte[] inputByteArray = new byte[2000000];
                int bytesRead;
                // ---------------------------------
                if (outputDirFile.exists() && !overwriteAllowed) {
                    row = "Error: IFS file  " + inputDirFile + "  was NOT copied to the existing file  " + targetPathString + ". Overwriting files is not allowed.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(noNodes);
                    return "ERROR";
                }
                // Get input file CCSID attribute
                int inputFileCcsid = inputDirFile.getCCSID();
                // Target file CCSID attribute - not yet ready
                int outputFileCcsid;
                // -------------------------------------
                if (!outputDirFile.exists()) {
                    // If target file does not exist, create one and set its CCSID
                    // from the input file
                    outputDirFile.createNewFile();
                    outputDirFile.setCCSID(inputFileCcsid);
                }
                outputFileCcsid = outputDirFile.getCCSID();
                // Open input IFS file
                ifsInStream = new IFSFileInputStream(remoteServer, sourcePathString);
                // 
                if (ibmCcsid.equals("*DEFAULT") || outputFileCcsid == inputFileCcsid) {
                    ifsOutStream = new IFSFileOutputStream(remoteServer, targetPathString);
                    // Copy IFS file to IFS file reading input stream to byte
                    // array and using output stream for output
                    // Read first portion of bytes
                    bytesRead = ifsInStream.read(inputByteArray);
                    // Repeat if at least one byte was read
                    while (bytesRead > 0) {
                        // Write out bytes read before
                        ifsOutStream.write(inputByteArray, 0, bytesRead);
                        // Read next portion of bytes
                        bytesRead = ifsInStream.read(inputByteArray);
                    }
                    // Close files
                    ifsOutStream.close();
                    ifsInStream.close();
                    if (fromWalk) {
                        row = "Info: IFS file  " + sourcePathString + "  was copied unchanged (binary) to IFS file  " + targetPathString + ". " + outputFileCcsid + " -> " + outputFileCcsid + ".";
                    } else {
                        row = "Comp: IFS file  " + sourcePathString + "  was copied unchanged (binary) to IFS file  " + targetPathString + ". " + outputFileCcsid + " -> " + outputFileCcsid + ".";
                    }
                // 
                } else {
                    // 
                    // Conversion from source IFS file's CCSID to target IFS file's CCSID
                    // ----------
                    // Open output IFS file
                    ifsOutStream = new IFSFileOutputStream(remoteServer, targetPathString, outputFileCcsid);
                    // Copy IFS file to IFS file reading input stream to byte
                    // array and using byte array for output
                    // Read first portion of bytes
                    bytesRead = ifsInStream.read(inputByteArray);
                    // Repeat if at least one byte was read
                    while (bytesRead > 0) {
                        // Convert input byte array with input CCSID to String
                        // (UTF-16)
                        AS400Text textConverter = new AS400Text(bytesRead, inputFileCcsid, remoteServer);
                        String text = (String) textConverter.toObject(inputByteArray);
                        // Convert data from String (UTF-16) to outpu byte array
                        // with output CCSID
                        AS400Text textConverter2 = new AS400Text(bytesRead, outputFileCcsid, remoteServer);
                        byte[] outputByteArray = (byte[]) textConverter2.toBytes(text);
                        // Write converted text in second byte array to output
                        // stream
                        ifsOutStream.write(outputByteArray, 0, outputByteArray.length);
                        // Read next byte array
                        bytesRead = ifsInStream.read(inputByteArray);
                        // Close files
                        ifsOutStream.close();
                        ifsInStream.close();
                        if (fromWalk) {
                            row = "Info: IFS file  " + sourcePathString + "  was copied to IFS file  " + targetPathString + ", Convert  " + inputFileCcsid + " -> " + outputFileCcsid;
                        } else {
                            row = "Comp: IFS file  " + sourcePathString + "  was copied to IFS file  " + targetPathString + ", Convert  " + inputFileCcsid + " -> " + outputFileCcsid;
                        }
                    }
                }
                mainWindow.msgVector.add(row);
                mainWindow.showMessages(nodes);
                return "";
            } catch (Exception exc) {
                exc.printStackTrace();
                row = "Error: Copying to IFS file " + targetPathString + "  -  " + exc.toString();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages(nodes);
                return "ERROR";
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: Copying to IFS file " + targetPathString + "  -  " + exc.toString();
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(nodes);
        return "ERROR";
    }
    return "";
}
Also used : IFSFileOutputStream(com.ibm.as400.access.IFSFileOutputStream) AS400Text(com.ibm.as400.access.AS400Text) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream)

Example 4 with IFSFileInputStream

use of com.ibm.as400.access.IFSFileInputStream in project IBMiProgTool by vzupka.

the class Copy_IBMi_PC method copyToPcFile.

/**
 * Copying IBM i IFS file or Source member or Save file to PC file;
 * If the PC file does not exist, one is created.
 *
 * @param pcPathString
 * @param as400PathString
 * @param fromWalk
 * @return
 */
protected String copyToPcFile(String as400PathString, String pcPathString, boolean fromWalk) {
    // Path to PC file
    Path pcFilePath = Paths.get(pcPathString);
    IFSFile ifsDirFile = new IFSFile(remoteServer, as400PathString);
    try {
        // Source physical file is a directory and cannot be copied to PC file
        if (ifsDirFile.isSourcePhysicalFile()) {
            row = "Error: Source physical file  " + as400PathString + "  cannot be copied to file  " + pcPathString + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages(noNodes);
            return "ERROR";
        }
        // IFS directory cannot be copied to PC file
        if (ifsDirFile.isDirectory()) {
            row = "Error: IFS directory  " + as400PathString + "  cannot be copied to PC file  " + pcPathString + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages(noNodes);
            return "ERROR";
        }
        // Source physical file MEMBER:
        if (sourcePathString.startsWith("/QSYS.LIB/")) {
            extractNamesFromIfsPath(as400PathString);
            if (sourcePathString.endsWith(".MBR")) {
                // 
                if (pcPathString.endsWith(".savf")) {
                    row = "Error: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  cannot be copied to PC file  " + pcPathString + "  ending with .savf.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(noNodes);
                    return "ERROR";
                }
                // 
                // Member to PC file
                // ------
                msgText = copyFromSourceMember(remoteServer, sourcePathString, pcPathString);
                if (msgText.isEmpty()) {
                    row = "Comp: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  was copied to PC file  " + pcPathString + " using charset " + pcCharset + ".";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(nodes);
                    return "";
                } else {
                    row = "Comp File: Source member  " + libraryName + "/" + fileName + "(" + memberName + ")  was NOT copied to PC file  " + pcPathString + ".";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(noNodes);
                    return "ERROR";
                }
            } else // ---------
            if (ifsDirFile.toString().contains(".LIB") && ifsDirFile.toString().endsWith(".SAVF") && ifsDirFile.getSubtype().equals("SAVF")) {
                msgText = copyFromSaveFile(remoteServer, sourcePathString, pcPathString);
                return msgText;
            }
        } else {
            // From IFS stream file to PC file (no directories are involved)
            try {
                byte[] byteArray = new byte[2000000];
                int bytesRead;
                // ---------------------------------
                if (Files.exists(pcFilePath) && !properties.getProperty("OVERWRITE_FILE").equals("Y")) {
                    row = "Error: IFS file  " + ifsDirFile + "  was NOT copied to the existing file  " + pcPathString + ". Overwriting files is not allowed.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(noNodes);
                    return "ERROR";
                }
                // ------------------------------------
                if (Files.notExists(pcFilePath)) {
                    Files.createFile(pcFilePath);
                }
                // IFS file with suffix .savf cannot be copied to PC file with different suffix
                if (sourcePathString.endsWith(".savf") && !pcPathString.endsWith(".savf")) {
                    row = "Error: IFS file  " + ifsDirFile + "  ending with suffix \".savf\" cannot be copied to the existing file  " + pcPathString + "  with a different suffix.";
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages(noNodes);
                    return "ERROR";
                }
                // Copy "save" file from IFS to PC file
                if (sourcePathString.endsWith(".savf") && pcPathString.endsWith(".savf")) {
                    // Copy the PC file to Save file using FTP (File Transfer Protocol)
                    AS400FTP ftp = new AS400FTP(remoteServer);
                    try {
                        // FTP Binary data transfer
                        // ftp.setDataTransferType(AS400FTP.BINARY); // not necessary when suffix is .savf
                        // FTP Get command
                        ftp.get(sourcePathString, pcPathString);
                        ftp.disconnect();
                        row = "Comp: IFS save file  " + sourcePathString + "  was copied to PC  save file  " + pcPathString + ".";
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                        return "";
                    } catch (Exception exc) {
                        exc.printStackTrace();
                        row = "Error: Copying IFS save file  " + sourcePathString + "  to PC  save file  " + pcPathString + "  failed:  " + exc.toString();
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                        return "ERROR";
                    }
                }
                // 
                if (pcCharset.equals("*DEFAULT") && ibmCcsid.equals("*DEFAULT")) {
                    // Open input IFS file
                    IFSFileInputStream ifsInStream = new IFSFileInputStream(remoteServer, as400PathString);
                    // Open the output PC file as buffered output stream
                    OutputStream os = Files.newOutputStream(pcFilePath, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
                    BufferedOutputStream bos = new BufferedOutputStream(os);
                    // Copy IFS file to PC file reading input stream to byte array and using byte buffer for output
                    // Read first portion of bytes
                    bytesRead = ifsInStream.read(byteArray);
                    // Repeat if at least one byte was read
                    while (bytesRead > 0) {
                        // Write out bytes read before
                        bos.write(byteArray, 0, bytesRead);
                        // Read next portion of bytes
                        bytesRead = ifsInStream.read(byteArray);
                    }
                    // Close files
                    bos.close();
                    ifsInStream.close();
                    if (fromWalk) {
                        row = "Info: IFS file  " + as400PathString + "  was copied unchanged (binary) to PC file  " + pcPathString + ".";
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                    } else {
                        row = "Comp: IFS file  " + as400PathString + "  was copied unchanged (binary) to PC file  " + pcPathString + ".";
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                    }
                // 
                // Data conversion is done
                // -----------------------
                } else {
                    // 
                    IFSFile ifsFile = new IFSFile(remoteServer, as400PathString);
                    if (ibmCcsid.equals("*DEFAULT")) {
                        // CCSID attribute of the input file
                        ibmCcsidInt = ifsFile.getCCSID();
                    }
                    // Open input IFS file
                    IFSFileInputStream ifsInStream = new IFSFileInputStream(remoteServer, as400PathString);
                    // Open output text file
                    if (pcCharset.equals("*DEFAULT")) {
                        pcCharset = "ISO-8859-1";
                    }
                    BufferedWriter outfileText = Files.newBufferedWriter(pcFilePath, Charset.forName(pcCharset), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
                    // Copy IFS file to PC file reading input stream to byte array and using byte buffer for output
                    // Read first portion of bytes
                    bytesRead = ifsInStream.read(byteArray);
                    // Repeat if at least one byte was read
                    while (bytesRead > 0) {
                        // Convert input file data using "IBM i CCSID" parameter
                        AS400Text textConverter = new AS400Text(bytesRead, ibmCcsidInt, remoteServer);
                        // Convert byte array buffer to translated data text
                        String str = (String) textConverter.toObject(byteArray);
                        String translatedData = new String(str.getBytes(pcCharset), pcCharset);
                        // Write translated data to the text file
                        outfileText.write(translatedData);
                        // Read next byte array
                        bytesRead = ifsInStream.read(byteArray);
                    }
                    // Close files
                    outfileText.close();
                    ifsInStream.close();
                    if (fromWalk) {
                        row = "Info: IFS file  " + as400PathString + "  was copied to PC file  " + pcPathString + ",  " + ibmCcsid + " -> " + pcCharset + ".";
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                    } else {
                        row = "Comp: IFS file  " + as400PathString + "  was copied to PC file  " + pcPathString + ",  " + ibmCcsid + " -> " + pcCharset + ".";
                        mainWindow.msgVector.add(row);
                        mainWindow.showMessages(noNodes);
                    }
                }
                return "";
            } catch (Exception exc) {
                exc.printStackTrace();
                row = "Error: Copying to PC file " + pcPathString + "  failed.  -  " + exc.toString();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages(noNodes);
                return "ERROR";
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: Copying to PC file " + pcPathString + "  -  " + exc.toString();
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(noNodes);
        return "ERROR";
    }
    return "";
}
Also used : Path(java.nio.file.Path) AS400Text(com.ibm.as400.access.AS400Text) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) AS400FTP(com.ibm.as400.access.AS400FTP) BufferedOutputStream(java.io.BufferedOutputStream) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream) BufferedWriter(java.io.BufferedWriter)

Example 5 with IFSFileInputStream

use of com.ibm.as400.access.IFSFileInputStream in project IBMiProgTool by vzupka.

the class SearchWindow method readIfsFile.

/**
 * Read IFS file data into text area.
 *
 * @return
 */
protected JTextArea readIfsFile() {
    try {
        IFSFile ifsFile = new IFSFile(remoteServer, mainWindow.sourcePathString);
        int attributeCCSID = ifsFile.getCCSID();
        byte[] inputBuffer = new byte[100000];
        byte[] workBuffer = new byte[100000];
        try (IFSFileInputStream inputStream = new IFSFileInputStream(remoteServer, mainWindow.sourcePathString)) {
            int bytesRead = inputStream.read(inputBuffer);
            while (bytesRead != -1) {
                for (int idx = 0; idx < bytesRead; idx++) {
                    // Copy input byte to output byte
                    workBuffer[idx] = inputBuffer[idx];
                }
                // Copy the printable part of the work array to a new buffer that will be written out.
                byte[] bufferToWrite = new byte[bytesRead];
                // Copy bytes from the work buffer to the new buffer
                for (int indx = 0; indx < bytesRead; indx++) {
                    bufferToWrite[indx] = workBuffer[indx];
                }
                // Create object for conversion from bytes to characters
                AS400Text textConverter = new AS400Text(bytesRead, attributeCCSID, remoteServer);
                // Convert byte array buffer to text line
                String textLine = (String) textConverter.toObject(bufferToWrite);
                // Append the line to text area
                textArea.append(textLine + NEW_LINE);
                // Read next input buffer
                bytesRead = inputStream.read(inputBuffer);
            }
            mainWindow.row = "Info: IFS file  " + mainWindow.sourcePathString + "  has CCSID  " + attributeCCSID + ".";
            mainWindow.msgVector.add(mainWindow.row);
            mainWindow.showMessages(mainWindow.nodes);
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        mainWindow.row = "Error: " + exc.toString();
        mainWindow.msgVector.add(mainWindow.row);
        mainWindow.showMessages(mainWindow.nodes);
    }
    // Remove message scroll listener (cancel scrolling to the last message)
    mainWindow.scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(mainWindow.messageScrollPaneAdjustmentListenerMax);
    return textArea;
}
Also used : AS400Text(com.ibm.as400.access.AS400Text) PatternSyntaxException(java.util.regex.PatternSyntaxException) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream)

Aggregations

AS400Text (com.ibm.as400.access.AS400Text)5 IFSFile (com.ibm.as400.access.IFSFile)5 IFSFileInputStream (com.ibm.as400.access.IFSFileInputStream)5 Point (java.awt.Point)2 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 BadLocationException (javax.swing.text.BadLocationException)2 AS400FTP (com.ibm.as400.access.AS400FTP)1 IFSFileOutputStream (com.ibm.as400.access.IFSFileOutputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedWriter (java.io.BufferedWriter)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 CannotRedoException (javax.swing.undo.CannotRedoException)1 CannotUndoException (javax.swing.undo.CannotUndoException)1