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:su.comp.bk.arch.io.FloppyControllerTest.java

@Test
public void testFloppyControllerOperations() throws Exception {
    //        floppyController.setDebugEnabled(true);
    // Mount disk image file
    byte[] testDiskImageData = mountTestDiskImage();
    Cpu cpu = computer.getCpu();// w w  w  .j a  v  a 2s . c om
    // Initialize FDD
    cpu.writeRegister(false, Cpu.R3, FDD_BLOCK_START_ADDR);
    assertTrue("can't initialize FDD", execute(0160010));
    // Single sector read
    int dataIndex = 0;
    cpu.writeMemory(true, FDD_BLOCK_DRIVE_NUM, FloppyDriveIdentifier.A.ordinal()); // Select drive
    for (int blockNumber = 0; blockNumber < FloppyController.BYTES_PER_DISK
            / FloppyController.BYTES_PER_SECTOR; blockNumber++) {
        cpu.writeRegister(false, Cpu.R0, blockNumber); // Sector number
        cpu.writeRegister(false, Cpu.R1, 0400); // Data length
        cpu.writeRegister(false, Cpu.R2, 01000); // Data read address
        assertTrue("can't read sector " + blockNumber, execute(0160004));
        assertTrue("sector " + blockNumber + " read error " + computer.readMemory(false, 052),
                !cpu.isPswFlagSet(Cpu.PSW_FLAG_C));
        // Check read data
        for (int address = 01000; address < 02000; address++) {
            assertEquals("sector " + blockNumber + " read error at address " + Integer.toOctalString(address),
                    testDiskImageData[dataIndex++] & 0377, computer.readMemory(true, address));
        }
    }
    // Multisector read
    dataIndex = 0;
    cpu.writeRegister(false, Cpu.R0, 0); // Sector number
    cpu.writeRegister(false, Cpu.R1, 020000); // Data length
    cpu.writeRegister(false, Cpu.R2, 040000); // Data read address
    assertTrue("can't read block", execute(0160004));
    for (int address = 040000; address < 0100000; address++) {
        assertEquals("block read error at address " + Integer.toOctalString(address),
                testDiskImageData[dataIndex++] & 0377, computer.readMemory(true, address));
    }
}

From source file:su.comp.bk.arch.io.FloppyControllerTest.java

private boolean execute(int address) {
    boolean isSuccess = false;
    Cpu cpu = computer.getCpu();/*from w ww .  j a v a 2s.  c o  m*/
    int initialAddress = cpu.readRegister(false, Cpu.PC);
    assertTrue("can't push PC to stack", cpu.push(initialAddress));
    cpu.writeRegister(false, Cpu.PC, address);
    int cpuOps = MAX_CPU_OPS;
    while (cpuOps-- > 0) {
        try {
            cpu.executeNextOperation();
        } catch (Exception e) {
            e.printStackTrace();
            fail("can't execute operation, PC: " + Integer.toOctalString(cpu.readRegister(false, Cpu.PC)));
        }
        if (initialAddress == cpu.readRegister(false, Cpu.PC)) {
            isSuccess = true;
            break;
        }
    }
    return isSuccess;
}

From source file:su.comp.bk.ui.BkEmuActivity.java

/**
 * Load image in bin format (address/length/data) from byte array.
 * @param imageData image data byte array
 * @throws IOException in case of loading error
 *//*from www. jav a  2  s .  c  o m*/
public int loadBinImage(byte[] imageData) throws IOException {
    if (imageData.length < 5 || imageData.length > 01000000) {
        throw new IllegalArgumentException("Invalid binary image file length: " + imageData.length);
    }
    DataInputStream imageDataInputStream = new DataInputStream(
            new ByteArrayInputStream(imageData, 0, imageData.length));
    lastBinImageAddress = (imageDataInputStream.readByte() & 0377)
            | ((imageDataInputStream.readByte() & 0377) << 8);
    lastBinImageLength = (imageDataInputStream.readByte() & 0377)
            | ((imageDataInputStream.readByte() & 0377) << 8);
    synchronized (computer) {
        for (int imageIndex = 0; imageIndex < lastBinImageLength; imageIndex++) {
            if (!computer.writeMemory(true, lastBinImageAddress + imageIndex, imageDataInputStream.read())) {
                throw new IllegalStateException("Can't write binary image data to address: 0"
                        + Integer.toOctalString(lastBinImageAddress) + imageIndex);
            }
        }
    }
    Log.d(TAG, "loaded bin image file: address 0" + Integer.toOctalString(lastBinImageAddress) + ", length: "
            + lastBinImageLength);
    return lastBinImageAddress;
}

From source file:tachyon.shell.command.ChmodCommand.java

/**
 * Changes the permissions of directory or file with the path specified in args.
 *
 * @param path The {@link TachyonURI} 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
 * @throws IOException if command failed
 *//*from w ww .j a v a  2 s . co m*/
private void chmod(TachyonURI path, String modeStr, boolean recursive) throws IOException {
    short newPermission = 0;
    try {
        newPermission = Short.parseShort(modeStr, 8);
        SetAttributeOptions options = SetAttributeOptions.defaults().setPermission(newPermission)
                .setRecursive(recursive);
        mFileSystem.setAttribute(path, options);
        System.out.println("Changed permission of " + path + " to " + Integer.toOctalString(newPermission));
    } catch (Exception e) {
        throw new IOException("Failed to changed permission of  " + path + " to "
                + Integer.toOctalString(newPermission) + " : " + e.getMessage());
    }
}

From source file:zang.jiagu.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) 
 *///  ww w . jav  a 2 s. c  o  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, JiaguBaoUtil.revert(tarEntry.getName()));
            } else {
                String fileName = StringUtils.substringAfterLast(tarEntry.getName(), "/");
                if (StringUtils.isBlank(fileName)) {
                    fileName = StringUtils.substringAfterLast(tarEntry.getName(), "\\");
                }
                f = new File(baseDir, JiaguBaoUtil.revert(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();
    }
}