Package org.wso2.carbon

Examples of org.wso2.carbon.CarbonException


     *
     * @throws IOException if the file is already open for either appending or reading, if the file does not exist, if the file cannot be opened for any other file system specific reason.
     */
    public void jsFunction_openForReading() throws CarbonException {
        if (writer != null)
            throw new CarbonException(
                    "Cannot read from the already writing file. Please close the file beforehand by calling close().");
        if (reader == null) {
            try {
                reader = new BufferedReader(new FileReader(file));
            } catch (FileNotFoundException e) {
                throw new CarbonException(e);
            }
        }
    }
View Full Code Here


        if (writer != null) {
            try {
                writer.write(Context.toString(object));
                writer.flush();
            } catch (IOException e) {
                throw new CarbonException(e);
            }
        } else {
            throw new CarbonException(
                    "File not open for writing. Please call openFileFor{Writing|Appending}() accordingly beforehand. ");
        }
    }
View Full Code Here

        jsFunction_write(object);
        try {
            writer.newLine();
            writer.flush();
        } catch (IOException e) {
            throw new CarbonException(e);
        }
    }
View Full Code Here

                    if (index < noOfCharacters) {
                        buffer = new char[noOfCharacters - index];
                    }
                }
            } catch (IOException e) {
                throw new CarbonException(e);
            }
            return buffer2.toString();
        }
        throw new CarbonException(
                "File not open for reading. Please call openFileForReading() beforehand. ");
    }
View Full Code Here

            // Checking whether a file with the same name exists
            File file = new File(scriptsFolder, fileName);
            if (file.exists() && !file.delete()) {
                /*throw new CarbonException("A Service JavaScript file with the same name already " +
                        "exists in the remote Mashup Server.");  */
                throw new CarbonException("Unable to delete file " + file.getName());
            }
            MashupArchiveManupulator archiveManupulator = new MashupArchiveManupulator();
            // Extract the uploaded mashup archive to the scripts folder.
            try {
                archiveManupulator.extractFromStream(dataHandler.getInputStream(), scriptsFolder
                        .getAbsolutePath());
            } catch (IOException e) {
                throw new CarbonException(e);
            }
        } else {
            throw new CarbonException("Cannot find the repository in the Mashup server.");
        }
    }
View Full Code Here

        }
        if (reader != null) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new CarbonException(e);
            }
        }
        throw new CarbonException(
                "File not open for reading. Please call openFileForReading() beforehand. ");
    }
View Full Code Here

                }
                reader.close();
                return stringBuffer.toString();
            }
        } catch (IOException e) {
            throw new CarbonException(e);
        }
        throw new CarbonException(
                "File not open for reading. Please call openFileForReading() beforehand. ");
    }
View Full Code Here

            } else if (reader != null) {
                reader.close();
                reader = null;
            }
        } catch (IOException e) {
            throw new CarbonException(e);
        }
    }
View Full Code Here

     */
    public boolean jsFunction_createFile() throws CarbonException {
        if (!file.exists()) {
            File parentFile = file.getParentFile();
            if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
                throw new CarbonException("Unable to create directory " + parentFile.getName());
            }
            try {
                if(file.createNewFile()) {
                    return true;
                } else {
                    throw new CarbonException("Unable to create file " + file.getName());
                }
            } catch (IOException e) {
                throw new CarbonException(e);
            }
        }
        return false;
    }
View Full Code Here

        try {

            if (arguments[0] instanceof String) {
                fileName = FilenameUtils.normalizeNoEndSeparator((String) arguments[0]);
                if (fileName == null) {
                    throw new CarbonException(
                            "FileHostObject : Illegal file path, Cannot navigate away from resources directory");
                }
            } else {
                throw new CarbonException(
                        "Invalid parameter. Expecting destination file location as a string.");
            }

            BufferedReader source = new BufferedReader(new FileReader(fileHostObject.file));

            //Creating the new file
            Object object = cx.getThreadLocal(MashupConstants.AXIS2_SERVICE);
            AxisService axisService;
            if (object instanceof AxisService) {
                axisService = (AxisService) object;
            } else {
                throw new CarbonException("Error obtaining the AxisService.");
            }

            Object resourceFileObject = axisService
                    .getParameterValue(MashupConstants.RESOURCES_FOLDER);
            File resourceFolder;
            if (resourceFileObject != null && resourceFileObject instanceof File) {
                resourceFolder = (File) resourceFileObject;
            } else {
                throw new CarbonException("Resources folder not found.");
            }

            File newFile = new File(resourceFolder, fileName);
            if (newFile.isDirectory()) {
                throw new CarbonException(
                        "Given path is not a File. This object does not support directories.");
            }

            //Creating the file and directories
            if (!newFile.exists()) {
                File parentFile = newFile.getParentFile();
                if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
                    throw new CarbonException("Unable to create directory " + parentFile.getName());
                }
            }

            BufferedWriter destination = new BufferedWriter(new FileWriter(newFile));

            String str;

            // Copying contents to new location
            while ((str = source.readLine()) != null) {
                destination.write(str);
                destination.newLine();
            }
            source.close();

            destination.flush();
            destination.close();

            //Delete the source file
            if(!fileHostObject.file.delete()) {
                throw new CarbonException("Unable to delete file " + fileHostObject.file.getName());
            }

            //Point to the new file
            fileHostObject.file = newFile;

            result = true;
        } catch (IOException e) {
            throw new CarbonException(e);
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.CarbonException

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.