Package io.apigee.trireme.core.internal

Examples of io.apigee.trireme.core.internal.NodeOSException


                }
                Files.createLink(dest, src);
                return new Object[] { Context.getUndefinedValue(), Context.getUndefinedValue() };

            } catch (IOException ioe) {
                throw new NodeOSException(getErrorCode(ioe), ioe, destPath);
            }
        }
View Full Code Here


        {
            Path dest = translatePath(destPath);
            Path src = translatePath(srcPath);

            if (dest == null) {
                throw new NodeOSException(Constants.EPERM, "Attempt to link file above filesystem root");
            }

            // "symlink" supports relative paths. But now that we have checked to make sure that we're
            // not trying to link an "illegal" path, we can just use the original path if it is relative.
            Path origSrc = Paths.get(srcPath);
            if (!origSrc.isAbsolute()) {
                src = origSrc;
            }

            try {
                if (log.isDebugEnabled()) {
                    log.debug("symlink from {} to {}",
                              src, dest);
                }

                Files.createSymbolicLink(dest, src);
                return new Object[] { Context.getUndefinedValue(), Context.getUndefinedValue() };

            } catch (IOException ioe) {
                throw new NodeOSException(getErrorCode(ioe), ioe, destPath);
            }
        }
View Full Code Here

                    result = target.toString();
                }
                return new Object[] { Context.getUndefinedValue(), result };
            } catch (IOException ioe) {
                log.debug("IOException: {}", ioe);
                throw new NodeOSException(getErrorCode(ioe), ioe, pathStr);
            }
        }
View Full Code Here

        private File translatePath(String path)
            throws NodeOSException
        {
            File trans = runner.translatePath(path);
            if (trans == null) {
                throw new NodeOSException(Constants.ENOENT);
            }
            return trans;
        }
View Full Code Here

            FileHandle handle = descriptors.get(fd);
            if (handle == null) {
                if (log.isDebugEnabled()) {
                    log.debug("FD {} is not a valid handle", fd);
                }
                throw new NodeOSException(Constants.EBADF);
            }
            return handle;
        }
View Full Code Here

            FileHandle h = ensureHandle(fd);
            if (h.file == null) {
                if (log.isDebugEnabled()) {
                    log.debug("FD {} is not a valid handle or regular file", fd);
                }
                throw new NodeOSException(Constants.EBADF);
            }
            return h;
        }
View Full Code Here

                    justCreated = path.createNewFile();
                } catch (IOException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Error in createNewFile: {}", e, e);
                    }
                    throw new NodeOSException(Constants.EIO, e);
                }
                if (justCreated) {
                    setMode(path, mode);
                } else if ((flags & Constants.O_EXCL) != 0) {
                    NodeOSException ne = new NodeOSException(Constants.EEXIST);
                    ne.setPath(pathStr);
                    throw ne;
                }
            } else if (!path.exists()) {
                NodeOSException ne = new NodeOSException(Constants.ENOENT);
                ne.setPath(pathStr);
                throw ne;
            }

            RandomAccessFile file = null;
            if (path.isFile()) {
                // Only open the file if it's actually a file -- we can still have an FD to a directory
                String modeStr;
                if ((flags & Constants.O_RDWR) != 0) {
                    modeStr = "rw";
                } else if ((flags & Constants.O_WRONLY) != 0) {
                    // Java does not have write-only...
                    modeStr = "rw";
                } else {
                    modeStr = "r";
                }
                if ((flags & Constants.O_SYNC) != 0) {
                    // And Java does not have read-only with sync either
                    modeStr = "rws";
                }

                try {
                    if (log.isDebugEnabled()) {
                        log.debug("Opening {} with {}", path.getPath(), modeStr);
                    }
                    file = new RandomAccessFile(path, modeStr);
                    if ((flags & Constants.O_TRUNC) != 0) {
                        file.setLength(0L);
                    } else if (((flags & Constants.O_APPEND) != 0) && (file.length() > 0)) {
                        file.seek(file.length());
                    }
                } catch (FileNotFoundException fnfe) {
                    // We should only get here if O_CREAT was NOT set
                    if (log.isDebugEnabled()) {
                        log.debug("File not found: {}", path);
                    }
                    throw new NodeOSException(Constants.ENOENT);
                } catch (IOException ioe) {
                    if (log.isDebugEnabled()) {
                        log.debug("I/O error: {}", ioe, ioe);
                    }
                    throw new NodeOSException(Constants.EIO, ioe);
                }
            }

            Context.enter();
            try {
View Full Code Here

                if (handle.file != null) {
                    handle.file.close();
                }
                descriptors.remove(fd);
            } catch (IOException ioe) {
                throw new NodeOSException(Constants.EIO, ioe);
            }
        }
View Full Code Here

                              off, len, pos, count);
                }
                return new Object[] { Context.getUndefinedValue(), count, buf };

            } catch (IOException ioe) {
                throw new NodeOSException(Constants.EIO, ioe);
            }
        }
View Full Code Here

                    log.debug("write({}, {}, {})", off, len, pos);
                }
                return new Object[] { Context.getUndefinedValue(), len, buf };

            } catch (IOException ioe) {
                throw new NodeOSException(Constants.EIO, ioe);
            }
        }
View Full Code Here

TOP

Related Classes of io.apigee.trireme.core.internal.NodeOSException

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.