當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtils類代碼示例

本文整理匯總了Java中sun.misc.IOUtils的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils類的具體用法?Java IOUtils怎麽用?Java IOUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IOUtils類屬於sun.misc包,在下文中一共展示了IOUtils類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkTimestamp

import sun.misc.IOUtils; //導入依賴的package包/類
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readFully(is, -1, true);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
開發者ID:ojdkbuild,項目名稱:lookaside_java-1.8.0-openjdk,代碼行數:26,代碼來源:TimestampCheck.java

示例2: getHostName

import sun.misc.IOUtils; //導入依賴的package包/類
private static String getHostName()
{
    String hostname = System.getenv().get("HOSTNAME");
    if (hostname == null)
    {
        try
        {
            final Process hostnameProcess = Runtime.getRuntime().exec("hostname");
            final String processOutput = new String(IOUtils.readFully(hostnameProcess.getInputStream(), Integer.MAX_VALUE, false), StandardCharsets.US_ASCII);
            hostname = processOutput.replace("\n", "").replace("\r", "").trim();
        }
        catch (final IOException ignored)
        {
            //ignored
        }
    }
    return hostname;
}
 
開發者ID:TransFICC,項目名稱:influx-jmh-reporter,代碼行數:19,代碼來源:CommandLineArgs.java

示例3: indexJar

import sun.misc.IOUtils; //導入依賴的package包/類
private List<ClassNode> indexJar() {
    ArrayList<ClassNode> classNodes = new ArrayList<ClassNode>();
    Enumeration<JarEntry> enumeration = jarFile.entries();
    while (enumeration.hasMoreElements()) {
        JarEntry jarEntry = enumeration.nextElement();
        if (jarEntry != null) {
            if (jarEntry.getName().endsWith(".class")) {
                try {
                    byte[] classBytes = IOUtils.readFully(jarFile.getInputStream(jarEntry), -1,
                            false);
                    ClassReader classReader = new ClassReader(classBytes);
                    ClassNode classNode = new ClassNode();
                    classReader.accept(classNode, 0);
                    classNodes.add(classNode);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return classNodes;
}
 
開發者ID:PizzaCrust,項目名稱:GraphiteMappings,代碼行數:23,代碼來源:MappingsBase.java

示例4: asmTest

import sun.misc.IOUtils; //導入依賴的package包/類
@Test
public void asmTest() throws Exception {
    JvmClass jvmClass = new JvmClass(IOUtils.readFully(getClass().getClassLoader()
            .getResourceAsStream("passion/test/AsmMethodTest$ExampleClass.class"), -1,
            false));
    jvmClass.getMethods().forEach((bytecodeMethod -> {
        if (bytecodeMethod.asm().name.equals("meow") && bytecodeMethod.getDescriptor()
                .getArguments().length == 0) {
            System.out.println("Found meow");
            bytecodeMethod.getInvocations().forEach((invocation -> System.out.println("Invoke: " + invocation.getOwner().jvm() + ": " +
                    invocation.getName() + ": " + invocation.getDescriptor()
                    .getReturnType().jvm())));
            Invocation invoke = Invocation.invokeStatic(bytecodeMethod, OtherClass.class
                    .getName(), "ok", "()V");
            bytecodeMethod.injectAllEndpoints(invoke, false);
        }
    }));
    File output = new File("output.class");
    System.out.println("output = " + output.getAbsolutePath());
    jvmClass.toFile(output);
}
 
開發者ID:PizzaCrust,項目名稱:Passion,代碼行數:22,代碼來源:AsmMethodTest.java

示例5: getBytes

import sun.misc.IOUtils; //導入依賴的package包/類
private static byte[] getBytes(URL url) throws IOException {
    URLConnection uc = url.openConnection();
    if (uc instanceof java.net.HttpURLConnection) {
        java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
        int code = huc.getResponseCode();
        if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
            throw new IOException("open HTTP connection failed.");
        }
    }
    int len = uc.getContentLength();
    InputStream in = new BufferedInputStream(uc.getInputStream());

    byte[] b;
    try {
        b = IOUtils.readFully(in, len, true);
    } finally {
        in.close();
    }
    return b;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:21,代碼來源:MethodUtil.java

示例6: readAuth

import sun.misc.IOUtils; //導入依賴的package包/類
AuthorizationDataEntry[] readAuth() throws IOException {
    int num, adtype, adlength;
    num = readLength4();
    if (num > 0) {
        List<AuthorizationDataEntry> auData = new ArrayList<>();
        byte[] data = null;
        for (int i = 0; i < num; i++) {
            adtype = read(2);
            adlength = readLength4();
            data = IOUtils.readFully(this, adlength, true);
            auData.add(new AuthorizationDataEntry(adtype, data));
        }
        return auData.toArray(new AuthorizationDataEntry[auData.size()]);
    }
    else return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:CCacheInputStream.java

示例7: getBytes

import sun.misc.IOUtils; //導入依賴的package包/類
private static byte[] getBytes(URL url) throws IOException {
    URLConnection uc = url.openConnection();
    if (uc instanceof java.net.HttpURLConnection) {
        java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
        int code = huc.getResponseCode();
        if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
            throw new IOException("open HTTP connection failed.");
        }
    }
    int len = uc.getContentLength();

    // Fixed #4507227: Slow performance to load
    // class and resources. [stanleyh]
    //
    // Use buffered input stream [stanleyh]
    InputStream in = new BufferedInputStream(uc.getInputStream());

    byte[] b;
    try {
        b = IOUtils.readFully(in, len, true);
    } finally {
        in.close();
    }
    return b;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:AppletClassLoader.java

示例8: initGame

import sun.misc.IOUtils; //導入依賴的package包/類
/**
 * Method which is called at the beginning of the client's communication
 *
 * Communicates with Server.ClientChecker
 *
 * Reads initData; mapsize, this client's id, and current state of the sections
 * @throws IOException if communication fails
 */
private static void initGame() throws IOException {
    DataInputStream in = new DataInputStream(CLIENT.getInputStream());
    PrintStream out = new PrintStream(CLIENT.getOutputStream());

    // write requestType
    out.println(Server.CONST_PLAY);
    System.out.println("DBG:Play");

    // write requested map
    out.println(_MAP);
    System.out.println("DBG:Map");

    // read gameData

    // mapsize
    mapsize = in.readInt();
    System.out.println("DBG:Size "+mapsize);

    // clientId
    clientId = in.readInt();
    System.out.println("DBG:id "+clientId);
    // amount of bytes that will be read, state
    int stateCount = in.readInt();
    System.out.println("DBG:stateLength "+stateCount);

    // read stateData
    byte[] stateData = IOUtils.readFully(in, stateCount, true);
    System.out.println("DBG:StateData\n"+Arrays.toString(stateData));


    // init CLIENT_GUI
    CLIENT_GUI = new ClientGUI(mapsize, stateData);
    CLIENT_GUI.setTitle(ManagementFactory.getRuntimeMXBean().getName()+"  Map: "+_MAP+"  ID:"+clientId);

    // tells server that client is ready
    out.write(1);
    System.out.println("DBG:Confirmed");
}
 
開發者ID:MEstfeller,項目名稱:Invasion,代碼行數:47,代碼來源:Client.java

示例9: sendBackupData

import sun.misc.IOUtils; //導入依賴的package包/類
@Override
public int sendBackupData(int numBytes) {

    if (backupState == null) {
        Log.e(TAG, "Attempted sendBackupData() before performFullBackup()");
        return TRANSPORT_ERROR;
    }

    long bytesTransferred = backupState.getBytesTransferred() + numBytes;

    if (bytesTransferred > configuration.getBackupSizeQuota()) {
        return TRANSPORT_QUOTA_EXCEEDED;
    }

    InputStream inputStream = backupState.getInputStream();
    ZipOutputStream outputStream = backupState.getOutputStream();

    try {
        outputStream.write(IOUtils.readFully(inputStream, numBytes, true));
        backupState.setBytesTransferred(bytesTransferred);

    } catch (IOException ex) {
        Log.e(TAG, "Error handling backup data for " + backupState.getPackageName() + ": ", ex);
        return TRANSPORT_ERROR;
    }
    return TRANSPORT_OK;
}
 
開發者ID:stevesoltys,項目名稱:backup,代碼行數:28,代碼來源:ContentProviderBackupComponent.java

示例10: readKey

import sun.misc.IOUtils; //導入依賴的package包/類
EncryptionKey readKey(int version) throws IOException {
    int keyType, keyLen;
    keyType = read(2);
    if (version == KRB5_FCC_FVNO_3)
        read(2); /* keytype recorded twice in fvno 3 */
    keyLen = readLength4();
    byte[] bytes = IOUtils.readFully(this, keyLen, true);
    return new EncryptionKey(bytes, keyType, new Integer(version));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:CCacheInputStream.java

示例11: readData

import sun.misc.IOUtils; //導入依賴的package包/類
byte[] readData() throws IOException {
    int length;
    length = readLength4();
    if (length == 0) {
        return null;
    } else {
        return IOUtils.readFully(this, length, true);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:CCacheInputStream.java


注:本文中的sun.misc.IOUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。