Example usage for java.lang Long toOctalString

List of usage examples for java.lang Long toOctalString

Introduction

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

Prototype

public static String toOctalString(long i) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Long.toOctalString(10));
}

From source file:com.yanzhenjie.nohttp.cache.CacheEntity.java

/**
 * @return the localExpire.
 */
public String getLocalExpireString() {
    return Long.toOctalString(localExpire);
}

From source file:com.livinglogic.ul4.FunctionFormat.java

public static String call(long obj, String formatString, Locale locale) {
    IntegerFormat format = new IntegerFormat(formatString);

    if (locale == null)
        locale = Locale.ENGLISH;//from w ww . ja v a2s . c  o  m

    String output = null;

    boolean neg = obj < 0;
    if (neg)
        obj = -obj;

    switch (format.type) {
    case 'b':
        output = Long.toBinaryString(obj);
        break;
    case 'c':
        if (neg || obj > 0xffff)
            throw new RuntimeException("value out of bounds for c format");
        output = Character.toString((char) obj);
        break;
    case 'd':
        output = Long.toString(obj);
        break;
    case 'o':
        output = Long.toOctalString(obj);
        break;
    case 'x':
        output = Long.toHexString(obj);
        break;
    case 'X':
        output = Long.toHexString(obj).toUpperCase();
        break;
    case 'n':
        // FIXME: locale formatting
        output = Long.toString(obj);
        break;
    }
    return formatIntegerString(output, neg, format);
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

private String newBase(String originalNumber, int originalBase, int base) throws SyntaxException {
    String[] split = originalNumber.split("\\.");
    if (split.length == 0) {
        split = new String[1];
        split[0] = "0";
    }/*  w  ww  .java  2  s.c  om*/
    if (split[0].isEmpty()) {
        split[0] = "0";
    }
    if (originalBase != 10) {
        split[0] = Long.toString(Long.parseLong(split[0], originalBase));
    }

    String wholeNumber = "";
    switch (base) {
    case 2:
        wholeNumber = Long.toBinaryString(Long.parseLong(split[0]));
        break;
    case 8:
        wholeNumber = Long.toOctalString(Long.parseLong(split[0]));
        break;
    case 10:
        wholeNumber = split[0];
        break;
    case 16:
        wholeNumber = Long.toHexString(Long.parseLong(split[0]));
        break;
    }
    if (split.length == 1)
        return wholeNumber.toUpperCase(Locale.US);

    // Catch overflow (it's a decimal, it can be (slightly) rounded
    if (split[1].length() > 13) {
        split[1] = split[1].substring(0, 13);
    }

    Solver solver = new Solver();
    double decimal = 0;
    if (originalBase != 10) {
        String decimalFraction = Long.toString(Long.parseLong(split[1], originalBase)) + "/" + originalBase
                + "^" + split[1].length();
        decimal = solver.eval(decimalFraction);
    } else {
        decimal = Double.parseDouble("0." + split[1]);
    }
    if (decimal == 0)
        return wholeNumber.toUpperCase(Locale.US);

    String decimalNumber = "";
    for (int i = 0; decimal != 0 && i <= 8; i++) {
        decimal *= base;
        int id = (int) Math.floor(decimal);
        decimal -= id;
        decimalNumber += Integer.toHexString(id);
    }
    return (wholeNumber + "." + decimalNumber).toUpperCase(Locale.US);
}

From source file:spade.reporter.Audit.java

private void handleOpen(Map<String, String> eventData, SYSCALL syscall) {
    // open() receives the following message(s):
    // - SYSCALL//from   w w w. ja v  a 2 s.c om
    // - CWD
    // - PATH with nametype CREATE (file operated on) or NORMAL (file operated on) or PARENT (parent of file operated on) or DELETE (file operated on) or UNKNOWN (only when syscall fails)
    // - PATH with nametype CREATE or NORMAL or PARENT or DELETE or UNKNOWN
    // - EOE

    //three syscalls can come here: OPEN (for files and pipes), OPENAT (for files and pipes), CREAT (only for files)

    Long flags = CommonFunctions.parseLong(eventData.get(AuditEventReader.ARG1), 0L);
    Long modeArg = CommonFunctions.parseLong(eventData.get(AuditEventReader.ARG2), 0L);

    String eventId = eventData.get(AuditEventReader.EVENT_ID);
    String pid = eventData.get(AuditEventReader.PID);
    String cwd = eventData.get(AuditEventReader.CWD);
    String fd = eventData.get(AuditEventReader.EXIT);
    String time = eventData.get(AuditEventReader.TIME);

    boolean isCreate = syscall == SYSCALL.CREATE || syscall == SYSCALL.CREAT; //TODO later on change only to CREAT only

    PathRecord pathRecord = getFirstPathWithNametype(eventData, AuditEventReader.NAMETYPE_CREATE);
    if (pathRecord == null) {
        isCreate = false;
        pathRecord = getFirstPathWithNametype(eventData, AuditEventReader.NAMETYPE_NORMAL);
        if (pathRecord == null) {
            log(Level.INFO, "Missing PATH record", null, time, eventId, syscall);
            return;
        }
    } else {
        isCreate = true;
    }

    String path = pathRecord.getPath();
    path = constructAbsolutePath(path, cwd, pid);

    if (path == null) {
        log(Level.INFO, "Missing CWD or PATH record", null, time, eventId, syscall);
        return;
    }

    Process process = processManager.handleProcessFromSyscall(eventData);
    ArtifactIdentifier artifactIdentifier = getArtifactIdentifierFromPathMode(path, pathRecord.getPathType(),
            time, eventId, syscall);
    AbstractEdge edge = null;
    boolean openedForRead = false;

    String flagsArgs = "";

    flagsArgs += ((flags & O_WRONLY) == O_WRONLY) ? "O_WRONLY|" : "";
    flagsArgs += ((flags & O_RDWR) == O_RDWR) ? "O_RDWR|" : "";
    // if neither write only nor read write then must be read only
    if (((flags & O_WRONLY) != O_WRONLY) && ((flags & O_RDWR) != O_RDWR)) {
        // O_RDONLY is 0, so always true
        flagsArgs += ((flags & O_RDONLY) == O_RDONLY) ? "O_RDONLY|" : "";
    }

    flagsArgs += ((flags & O_APPEND) == O_APPEND) ? "O_APPEND|" : "";
    flagsArgs += ((flags & O_TRUNC) == O_TRUNC) ? "O_TRUNC|" : "";
    flagsArgs += ((flags & O_CREAT) == O_CREAT) ? "O_CREAT|" : "";

    if (!flagsArgs.isEmpty()) {
        flagsArgs = flagsArgs.substring(0, flagsArgs.length() - 1);
    }

    if (isCreate) {
        artifactManager.artifactCreated(artifactIdentifier);
        syscall = SYSCALL.CREATE;
    }

    if ((flags & O_WRONLY) == O_WRONLY || (flags & O_RDWR) == O_RDWR || (flags & O_APPEND) == O_APPEND
            || (flags & O_TRUNC) == O_TRUNC) {
        if (!isCreate) {
            // If artifact not created
            artifactManager.artifactVersioned(artifactIdentifier);
        }
        artifactManager.artifactPermissioned(artifactIdentifier, pathRecord.getPermissions());
        Artifact vertex = putArtifactFromSyscall(eventData, artifactIdentifier);
        edge = new WasGeneratedBy(vertex, process);
        openedForRead = false;
    } else if ((flags & O_RDONLY) == O_RDONLY) {
        artifactManager.artifactPermissioned(artifactIdentifier, pathRecord.getPermissions());
        if (isCreate) {
            Artifact vertex = putArtifactFromSyscall(eventData, artifactIdentifier);
            edge = new WasGeneratedBy(vertex, process);
        } else {
            Artifact vertex = putArtifactFromSyscall(eventData, artifactIdentifier);
            edge = new Used(process, vertex);
        }
        openedForRead = true;
    } else {
        log(Level.INFO, "Unhandled value of FLAGS argument '" + flags + "'", null, time, eventId, syscall);
        return;
    }

    if (edge != null) {
        edge.addAnnotation(OPMConstants.EDGE_MODE, Long.toOctalString(modeArg));
        if (!flagsArgs.isEmpty()) {
            edge.addAnnotation(OPMConstants.EDGE_FLAGS, flagsArgs);
        }
        //everything happened successfully. add it to descriptors
        processManager.setFd(pid, fd, artifactIdentifier, openedForRead);

        putEdge(edge, getOperation(syscall), time, eventId, AUDIT_SYSCALL_SOURCE);
    }
}