Example usage for java.lang Integer toOctalString

List of usage examples for java.lang Integer toOctalString

Introduction

In this page you can find the example usage for java.lang Integer toOctalString.

Prototype

public static String toOctalString(int i) 

Source Link

Document

Returns a string representation of the integer argument as an unsigned integer in base 8.

Usage

From source file:alluxio.cli.fs.command.ChmodCommand.java

/**
 * Changes the permissions of directory or file with the path specified in args.
 *
 * @param path The {@link AlluxioURI} path as the input of the command
 * @param modeStr The new permission to be updated to the file or directory
 * @param recursive Whether change the permission recursively
 *//*  w w w  .ja v  a  2s.c  o m*/
private void chmod(AlluxioURI path, String modeStr, boolean recursive) throws AlluxioException, IOException {
    Mode mode = mParser.parse(modeStr);
    SetAttributeOptions options = SetAttributeOptions.defaults().setMode(mode).setRecursive(recursive);
    mFileSystem.setAttribute(path, options);
    System.out.println("Changed permission of " + path + " to " + Integer.toOctalString(mode.toShort()));
}

From source file:com.fjn.helper.common.util.StringUtil.java

/**
 * 10?2?8?16/*from   w  ww.ja va  2s. c  om*/
 * @param num
 * @return
 */
public static String dec2Bin_Oct_Hex(int num, int flag) {
    if (flag == 2) {
        return Integer.toBinaryString(num);
    } else if (flag == 8) {
        return Integer.toOctalString(num);
    } else if (flag == 16) {
        return Integer.toHexString(num);
    } else {
        return null;
    }
}

From source file:AsciiTable.java

/**
 * Creates the window's contents (the table)
 * /*from w  ww.j  a v  a2s  . co  m*/
 * @param composite the parent composite
 */
private void createContents(Composite composite) {
    composite.setLayout(new FillLayout());

    // The system font will not display the lower 32
    // characters, so create one that will
    createFont();

    // Create a table with visible headers
    // and lines, and set the font that we
    // created
    Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setRedraw(false);
    table.setFont(font);

    // Create the columns
    TableColumn[] columns = createColumns(table);

    for (int i = 0; i < MAX_CHARS; i++) {
        // Create a background color for this row
        colors[i] = new Color(table.getDisplay(), 255 - i, 127 + i, i);

        // Create the row in the table by creating
        // a TableItem and setting text for each
        // column
        int c = 0;
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(c++, String.valueOf((char) i));
        item.setText(c++, String.valueOf(i));
        item.setText(c++, Integer.toHexString(i).toUpperCase());
        item.setText(c++, Integer.toOctalString(i));
        item.setText(c++, Integer.toBinaryString(i));
        item.setText(c++, i < CHAR_NAMES.length ? CHAR_NAMES[i] : "");
        item.setBackground(colors[i]);
    }

    // Now that we've set the text into the columns,
    // we call pack() on each one to size it to the
    // contents.
    for (int i = 0, n = columns.length; i < n; i++) {
        columns[i].pack();
    }

    // Set redraw back to true so that the table
    // will paint appropriately
    table.setRedraw(true);
}

From source file:com.manydesigns.elements.fields.TextField.java

protected void valueToXhtmlEdit(XhtmlBuffer xb) {
    if (multiline) {
        xb.openElement("textarea");
        xb.addAttribute("id", id);
        xb.addAttribute("name", inputName);
        String htmlClass = fieldCssClass;
        if (textAreaWidth != null) {
            xb.addAttribute("cols", Integer.toString(textAreaWidth));
            xb.addAttribute("rows", Integer.toString(numRowTextArea(stringValue, textAreaWidth)));
            htmlClass += " mde-text-field-with-explicit-size";
        } else {//w ww.  j  ava  2s.  c o  m
            xb.addAttribute("rows", Integer.toOctalString(textAreaMinRows));
        }
        if (richText) {
            htmlClass += " mde-form-rich-text";
        }
        if (!StringUtils.isEmpty(htmlClass)) {
            xb.addAttribute("class", htmlClass);
        }
        xb.write(stringValue);
        xb.closeElement("textarea");
    } else {
        super.valueToXhtmlEdit(xb);
    }
}

From source file:ch.cyberduck.core.sftp.SFTPPath.java

protected void readAttributes(SFTPv3FileAttributes attributes) {
    if (null != attributes.size) {
        if (this.attributes().isFile()) {
            this.attributes().setSize(attributes.size);
        }/*www.  j a va 2 s.  c om*/
    }
    String perm = attributes.getOctalPermissions();
    if (null != perm) {
        try {
            String octal = Integer.toOctalString(attributes.permissions);
            this.attributes()
                    .setPermission(new Permission(Integer.parseInt(octal.substring(octal.length() - 4))));
        } catch (IndexOutOfBoundsException e) {
            log.warn(String.format("Failure parsing mode:%s", e.getMessage()));
        } catch (NumberFormatException e) {
            log.warn(String.format("Failure parsing mode:%s", e.getMessage()));
        }
    }
    if (null != attributes.uid) {
        this.attributes().setOwner(attributes.uid.toString());
    }
    if (null != attributes.gid) {
        this.attributes().setGroup(attributes.gid.toString());
    }
    if (null != attributes.mtime) {
        this.attributes().setModificationDate(Long.parseLong(attributes.mtime.toString()) * 1000L);
    }
    if (null != attributes.atime) {
        this.attributes().setAccessedDate(Long.parseLong(attributes.atime.toString()) * 1000L);
    }
    if (attributes.isSymlink()) {
        try {
            String target = this.getSession().sftp().readLink(this.getAbsolute());
            if (!target.startsWith(String.valueOf(Path.DELIMITER))) {
                target = Path
                        .normalize(this.getParent().getAbsolute() + String.valueOf(Path.DELIMITER) + target);
            }
            this.setSymlinkTarget(target);
            SFTPv3FileAttributes targetAttributes = this.getSession().sftp().stat(target);
            if (targetAttributes.isDirectory()) {
                this.attributes().setType(SYMBOLIC_LINK_TYPE | DIRECTORY_TYPE);
            } else if (targetAttributes.isRegularFile()) {
                this.attributes().setType(SYMBOLIC_LINK_TYPE | FILE_TYPE);
            }
        } catch (IOException e) {
            log.warn(String.format("Cannot read symbolic link target of %s:%s", this.getAbsolute(),
                    e.getMessage()));
            this.attributes().setType(FILE_TYPE);
        }
    }
}

From source file:com.michelin.cio.hudson.plugins.copytoslave.MyFilePath.java

/**
 * Full copy/paste of Hudson's {@link FilePath#readFromTar} method with
 * some tweaking (mainly the flatten behavior).
 *
 * @see hudson.FilePath#readFromTar(java.lang.String, java.io.File, java.io.InputStream) 
 *//*w w  w  .  j a v  a  2 s .  co m*/
public static void readFromTar(File baseDir, boolean flatten, InputStream in) throws IOException {
    Chmod chmodTask = null; // HUDSON-8155

    TarInputStream t = new TarInputStream(in);
    try {
        TarEntry tarEntry;
        while ((tarEntry = t.getNextEntry()) != null) {
            File f = null;

            if (!flatten || (!tarEntry.getName().contains("/") && !tarEntry.getName().contains("\\"))) {
                f = new File(baseDir, tarEntry.getName());
            } else {
                String fileName = StringUtils.substringAfterLast(tarEntry.getName(), "/");
                if (StringUtils.isBlank(fileName)) {
                    fileName = StringUtils.substringAfterLast(tarEntry.getName(), "\\");
                }
                f = new File(baseDir, fileName);
            }

            // dir processing
            if (!flatten && tarEntry.isDirectory()) {
                f.mkdirs();
            }
            // file processing
            else {
                if (!flatten && f.getParentFile() != null) {
                    f.getParentFile().mkdirs();
                }

                IOUtils.copy(t, f);

                f.setLastModified(tarEntry.getModTime().getTime());

                // chmod
                int mode = tarEntry.getMode() & 0777;
                if (mode != 0 && !Functions.isWindows()) // be defensive
                    try {
                        LIBC.chmod(f.getPath(), mode);
                    } catch (NoClassDefFoundError ncdfe) {
                        // be defensive. see http://www.nabble.com/-3.0.6--Site-copy-problem%3A-hudson.util.IOException2%3A--java.lang.NoClassDefFoundError%3A-Could-not-initialize-class--hudson.util.jna.GNUCLibrary-td23588879.html
                    } catch (UnsatisfiedLinkError ule) {
                        // HUDSON-8155: use Ant's chmod task
                        if (chmodTask == null) {
                            chmodTask = new Chmod();
                        }
                        chmodTask.setProject(new Project());
                        chmodTask.setFile(f);
                        chmodTask.setPerm(Integer.toOctalString(mode));
                        chmodTask.execute();
                    }
            }
        }
    } catch (IOException e) {
        throw new IOException2("Failed to extract to " + baseDir.getAbsolutePath(), e);
    } finally {
        t.close();
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.RootFile.java

public void chmod(int octal) {
    CommandParams params = new CommandParams();
    params.command = new String[] { "chmod", Integer.toOctalString(octal), getAbsolutePath() };

    CommandRunner cmd = new CommandRunner(params);
    cmd.start();// w  ww  . j a va 2 s  .  c  o  m
    CommandUtils.waitForCommand(cmd);

    CommandResult result = cmd.getResult();

    if (mAttemptRoot && (result == null || result.exitCode != 0)) {
        CommandUtils.runRootCommand("chmod " + Integer.toOctalString(octal) + " " + getAbsolutePath());
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.RootFile.java

public void recursiveChmod(int octal) {
    CommandParams params = new CommandParams();
    params.command = new String[] { "chmod", "-R", Integer.toOctalString(octal), mFile.getAbsolutePath() };

    CommandRunner cmd = new CommandRunner(params);
    cmd.start();/*from w  w w  .  j a v a  2 s .  c om*/
    CommandUtils.waitForCommand(cmd);

    CommandResult result = cmd.getResult();

    if (mAttemptRoot && (result == null || result.exitCode != 0)) {
        CommandUtils.runRootCommand("chmod -R " + Integer.toOctalString(octal) + " " + mFile.getAbsolutePath());
    }
}

From source file:com.tripadvisor.hadoop.HiveUtil.java

public String charToEscapedOctal(char c) {
    return "'\\" + StringUtils.leftPad(Integer.toOctalString(c), 3, '0') + "'";
}

From source file:fuse.okuyamafs.OkuyamaFilesystem.java

public int mknod(String path, int mode, int rdev) throws FuseException {
    log.info("mknod " + path + " " + mode + " " + rdev);
    // mode?8??3???????http://sourceforge.net/apps/mediawiki/fuse/index.php?title=Stat
    // 3??=>755??644??
    String modeStr = Integer.toOctalString(mode);
    String pathType = "";
    String fileBlockIdx = null;/*ww  w . j a  va  2 s  .c om*/
    if (modeStr.indexOf("100") == 0) {

        // Regular File
        pathType = "file";
        fileBlockIdx = "-1";
    } else if (modeStr.indexOf("40") == 0) {

        // Directory
        pathType = "dir";
    } else {
        return Errno.EINVAL;
    }

    String pathInfoStr = "";
    pathInfoStr = pathInfoStr + pathType;
    pathInfoStr = pathInfoStr + "\t" + "1";
    pathInfoStr = pathInfoStr + "\t" + "0";
    pathInfoStr = pathInfoStr + "\t" + "0";
    pathInfoStr = pathInfoStr + "\t" + "0";
    pathInfoStr = pathInfoStr + "\t" + (System.currentTimeMillis() / 1000L);
    pathInfoStr = pathInfoStr + "\t" + "0";
    pathInfoStr = pathInfoStr + "\t" + mode;
    pathInfoStr = pathInfoStr + "\t" + rdev;
    pathInfoStr = pathInfoStr + "\t" + System.nanoTime(); // realKeyNodeNo
    if (fileBlockIdx != null) {
        pathInfoStr = pathInfoStr + "\t" + fileBlockIdx;
    }

    try {
        if (!client.addPathDetail(path.trim(), pathInfoStr)) {
            return Errno.EEXIST;
        }
        if (!client.setDirAttribute(path.trim(), pathType)) {
            return Errno.EEXIST;
        }
    } catch (FuseException fe) {
        throw fe;
    } catch (Exception e) {
        new FuseException(e);
    }
    return 0;
}