Java Code Examples for sun.misc.IOUtils#readExactlyNBytes()

The following examples show how to use sun.misc.IOUtils#readExactlyNBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CCacheInputStream.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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.readExactlyNBytes(this, adlength);
            auData.add(new AuthorizationDataEntry(adtype, data));
        }
        return auData.toArray(new AuthorizationDataEntry[auData.size()]);
    }
    else return null;
}
 
Example 2
Source File: CCacheInputStream.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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.readExactlyNBytes(this, adlength);
            auData.add(new AuthorizationDataEntry(adtype, data));
        }
        return auData.toArray(new AuthorizationDataEntry[auData.size()]);
    }
    else return null;
}
 
Example 3
Source File: CCacheInputStream.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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.readExactlyNBytes(this, adlength);
            auData.add(new AuthorizationDataEntry(adtype, data));
        }
        return auData.toArray(new AuthorizationDataEntry[auData.size()]);
    }
    else return null;
}
 
Example 4
Source File: CCacheInputStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
byte[] readData() throws IOException {
    int length;
    length = readLength4();
    if (length == 0) {
        return null;
    } else {
        return IOUtils.readExactlyNBytes(this, length);
    }
}
 
Example 5
Source File: DerValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private DerInputStream init(boolean fullyBuffered, InputStream in,
    boolean allowBER) throws IOException {

    tag = (byte)in.read();
    byte lenByte = (byte)in.read();
    length = DerInputStream.getLength(lenByte, in);
    if (length == -1) { // indefinite length encoding found
        int readLen = in.available();
        int offset = 2;     // for tag and length bytes
        byte[] indefData = new byte[readLen + offset];
        indefData[0] = tag;
        indefData[1] = lenByte;
        DataInputStream dis = new DataInputStream(in);
        dis.readFully(indefData, offset, readLen);
        dis.close();
        DerIndefLenConverter derIn = new DerIndefLenConverter();
        in = new ByteArrayInputStream(derIn.convert(indefData));
        if (tag != in.read())
            throw new IOException
                    ("Indefinite length encoding not supported");
        length = DerInputStream.getDefiniteLength(in);
    }

    if (fullyBuffered && in.available() != length)
        throw new IOException("extra data given to DerValue constructor");

    byte[] bytes = IOUtils.readExactlyNBytes(in, length);

    buffer = new DerInputBuffer(bytes, allowBER);
    return new DerInputStream(buffer);
}
 
Example 6
Source File: CertificateRevokedException.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserialize the {@code CertificateRevokedException} instance.
 */
private void readObject(ObjectInputStream ois)
    throws IOException, ClassNotFoundException {
    // Read in the non-transient fields
    // (revocationDate, reason, authority)
    ois.defaultReadObject();

    // Defensively copy the revocation date
    revocationDate = new Date(revocationDate.getTime());

    // Read in the size (number of mappings) of the extensions map
    // and create the extensions map
    int size = ois.readInt();
    if (size == 0) {
        extensions = Collections.emptyMap();
    } else if (size < 0) {
        throw new IOException("size cannot be negative");
    } else {
        extensions = new HashMap<>(size > 20 ? 20 : size);
    }

    // Read in the extensions and put the mappings in the extensions map
    for (int i = 0; i < size; i++) {
        String oid = (String) ois.readObject();
        boolean critical = ois.readBoolean();
        byte[] extVal = IOUtils.readExactlyNBytes(ois, ois.readInt());
        Extension ext = sun.security.x509.Extension.newExtension
            (new ObjectIdentifier(oid), critical, extVal);
        extensions.put(oid, ext);
    }
}
 
Example 7
Source File: CCacheInputStream.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
byte[] readData() throws IOException {
    int length;
    length = readLength4();
    if (length == 0) {
        return null;
    } else {
        return IOUtils.readExactlyNBytes(this, length);
    }
}
 
Example 8
Source File: CertificateRevokedException.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserialize the {@code CertificateRevokedException} instance.
 */
private void readObject(ObjectInputStream ois)
    throws IOException, ClassNotFoundException {
    // Read in the non-transient fields
    // (revocationDate, reason, authority)
    ois.defaultReadObject();

    // Defensively copy the revocation date
    revocationDate = new Date(revocationDate.getTime());

    // Read in the size (number of mappings) of the extensions map
    // and create the extensions map
    int size = ois.readInt();
    if (size == 0) {
        extensions = Collections.emptyMap();
    } else if (size < 0) {
        throw new IOException("size cannot be negative");
    } else {
        extensions = new HashMap<>(size > 20 ? 20 : size);
    }

    // Read in the extensions and put the mappings in the extensions map
    for (int i = 0; i < size; i++) {
        String oid = (String) ois.readObject();
        boolean critical = ois.readBoolean();
        byte[] extVal = IOUtils.readExactlyNBytes(ois, ois.readInt());
        Extension ext = sun.security.x509.Extension.newExtension
            (new ObjectIdentifier(oid), critical, extVal);
        extensions.put(oid, ext);
    }
}
 
Example 9
Source File: DerValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private DerInputStream init(boolean fullyBuffered, InputStream in,
    boolean allowBER) throws IOException {

    tag = (byte)in.read();
    byte lenByte = (byte)in.read();
    length = DerInputStream.getLength(lenByte, in);
    if (length == -1) { // indefinite length encoding found
        int readLen = in.available();
        int offset = 2;     // for tag and length bytes
        byte[] indefData = new byte[readLen + offset];
        indefData[0] = tag;
        indefData[1] = lenByte;
        DataInputStream dis = new DataInputStream(in);
        dis.readFully(indefData, offset, readLen);
        dis.close();
        DerIndefLenConverter derIn = new DerIndefLenConverter();
        in = new ByteArrayInputStream(derIn.convert(indefData));
        if (tag != in.read())
            throw new IOException
                    ("Indefinite length encoding not supported");
        length = DerInputStream.getLength(in);
    }

    if (fullyBuffered && in.available() != length)
        throw new IOException("extra data given to DerValue constructor");

    byte[] bytes = IOUtils.readExactlyNBytes(in, length);

    buffer = new DerInputBuffer(bytes, allowBER);
    return new DerInputStream(buffer);
}
 
Example 10
Source File: DerValue.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private DerInputStream init(boolean fullyBuffered, InputStream in,
    boolean allowBER) throws IOException {

    tag = (byte)in.read();
    byte lenByte = (byte)in.read();
    length = DerInputStream.getLength(lenByte, in);
    if (length == -1) { // indefinite length encoding found
        int readLen = in.available();
        int offset = 2;     // for tag and length bytes
        byte[] indefData = new byte[readLen + offset];
        indefData[0] = tag;
        indefData[1] = lenByte;
        DataInputStream dis = new DataInputStream(in);
        dis.readFully(indefData, offset, readLen);
        dis.close();
        DerIndefLenConverter derIn = new DerIndefLenConverter();
        in = new ByteArrayInputStream(derIn.convert(indefData));
        if (tag != in.read())
            throw new IOException
                    ("Indefinite length encoding not supported");
        length = DerInputStream.getLength(in);
    }

    if (fullyBuffered && in.available() != length)
        throw new IOException("extra data given to DerValue constructor");

    byte[] bytes = IOUtils.readExactlyNBytes(in, length);

    buffer = new DerInputBuffer(bytes, allowBER);
    return new DerInputStream(buffer);
}
 
Example 11
Source File: CCacheInputStream.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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.readExactlyNBytes(this, keyLen);
    return new EncryptionKey(bytes, keyType, new Integer(version));
}
 
Example 12
Source File: CertificateRevokedException.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserialize the {@code CertificateRevokedException} instance.
 */
private void readObject(ObjectInputStream ois)
    throws IOException, ClassNotFoundException {
    // Read in the non-transient fields
    // (revocationDate, reason, authority)
    ois.defaultReadObject();

    // Defensively copy the revocation date
    revocationDate = new Date(revocationDate.getTime());

    // Read in the size (number of mappings) of the extensions map
    // and create the extensions map
    int size = ois.readInt();
    if (size == 0) {
        extensions = Collections.emptyMap();
    } else if (size < 0) {
        throw new IOException("size cannot be negative");
    } else {
        extensions = new HashMap<>(size > 20 ? 20 : size);
    }

    // Read in the extensions and put the mappings in the extensions map
    for (int i = 0; i < size; i++) {
        String oid = (String) ois.readObject();
        boolean critical = ois.readBoolean();
        byte[] extVal = IOUtils.readExactlyNBytes(ois, ois.readInt());
        Extension ext = sun.security.x509.Extension.newExtension
            (new ObjectIdentifier(oid), critical, extVal);
        extensions.put(oid, ext);
    }
}
 
Example 13
Source File: CCacheInputStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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.readExactlyNBytes(this, keyLen);
    return new EncryptionKey(bytes, keyType, new Integer(version));
}
 
Example 14
Source File: CertificateRevokedException.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserialize the {@code CertificateRevokedException} instance.
 */
private void readObject(ObjectInputStream ois)
    throws IOException, ClassNotFoundException {
    // Read in the non-transient fields
    // (revocationDate, reason, authority)
    ois.defaultReadObject();

    // Defensively copy the revocation date
    revocationDate = new Date(revocationDate.getTime());

    // Read in the size (number of mappings) of the extensions map
    // and create the extensions map
    int size = ois.readInt();
    if (size == 0) {
        extensions = Collections.emptyMap();
    } else if (size < 0) {
        throw new IOException("size cannot be negative");
    } else {
        extensions = new HashMap<>(size > 20 ? 20 : size);
    }

    // Read in the extensions and put the mappings in the extensions map
    for (int i = 0; i < size; i++) {
        String oid = (String) ois.readObject();
        boolean critical = ois.readBoolean();
        byte[] extVal = IOUtils.readExactlyNBytes(ois, ois.readInt());
        Extension ext = sun.security.x509.Extension.newExtension
            (new ObjectIdentifier(oid), critical, extVal);
        extensions.put(oid, ext);
    }
}
 
Example 15
Source File: DerValue.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private DerInputStream init(boolean fullyBuffered, InputStream in,
    boolean allowBER) throws IOException {

    tag = (byte)in.read();
    byte lenByte = (byte)in.read();
    length = DerInputStream.getLength(lenByte, in);
    if (length == -1) { // indefinite length encoding found
        int readLen = in.available();
        int offset = 2;     // for tag and length bytes
        byte[] indefData = new byte[readLen + offset];
        indefData[0] = tag;
        indefData[1] = lenByte;
        DataInputStream dis = new DataInputStream(in);
        dis.readFully(indefData, offset, readLen);
        dis.close();
        DerIndefLenConverter derIn = new DerIndefLenConverter();
        in = new ByteArrayInputStream(derIn.convert(indefData));
        if (tag != in.read())
            throw new IOException
                    ("Indefinite length encoding not supported");
        length = DerInputStream.getLength(in);
    }

    if (fullyBuffered && in.available() != length)
        throw new IOException("extra data given to DerValue constructor");

    byte[] bytes = IOUtils.readExactlyNBytes(in, length);

    buffer = new DerInputBuffer(bytes, allowBER);
    return new DerInputStream(buffer);
}
 
Example 16
Source File: NetClient.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] receive() throws IOException {
    byte[] lenField = new byte[4];
    int count = readFully(lenField, 4);

    if (count != 4) {
        if (Krb5.DEBUG) {
            System.out.println(
                ">>>DEBUG: TCPClient could not read length field");
        }
        return null;
    }

    int len = networkByteOrderToInt(lenField, 0, 4);
    if (Krb5.DEBUG) {
        System.out.println(
            ">>>DEBUG: TCPClient reading " + len + " bytes");
    }
    if (len <= 0) {
        if (Krb5.DEBUG) {
            System.out.println(
                ">>>DEBUG: TCPClient zero or negative length field: "+len);
        }
        return null;
    }

    try {
        return IOUtils.readExactlyNBytes(in, len);
    } catch (IOException ioe) {
        if (Krb5.DEBUG) {
            System.out.println(
                ">>>DEBUG: TCPClient could not read complete packet (" +
                len + "/" + count + ")");
        }
        return null;
    }
}
 
Example 17
Source File: CCacheInputStream.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
byte[] readData() throws IOException {
    int length;
    length = readLength4();
    if (length == 0) {
        return null;
    } else {
        return IOUtils.readExactlyNBytes(this, length);
    }
}
 
Example 18
Source File: CCacheInputStream.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public PrincipalName readPrincipal(int version) throws IOException, RealmException {
    int type, length, namelength, kret;
    String[] pname = null;
    String realm;
    /* Read principal type */
    if (version == KRB5_FCC_FVNO_1) {
        type = KRB5_NT_UNKNOWN;
    } else {
        type = read(4);
    }
    length = readLength4();
    List<String> result = new ArrayList<String>();
    /*
     * DCE includes the principal's realm in the count; the new format
     * does not.
     */
    if (version == KRB5_FCC_FVNO_1)
        length--;
    for (int i = 0; i <= length; i++) {
        namelength = readLength4();
        byte[] bytes = IOUtils.readExactlyNBytes(this, namelength);
        result.add(new String(bytes));
    }
    if (result.isEmpty()) {
        throw new IOException("No realm or principal");
    }
    if (isRealm(result.get(0))) {
        realm = result.remove(0);
        if (result.isEmpty()) {
            throw new IOException("No principal name components");
        }
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                new Realm(realm));
    }
    try {
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                Realm.getDefault());
    } catch (RealmException re) {
        return null;
    }
}
 
Example 19
Source File: CCacheInputStream.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public PrincipalName readPrincipal(int version) throws IOException, RealmException {
    int type, length, namelength, kret;
    String[] pname = null;
    String realm;
    /* Read principal type */
    if (version == KRB5_FCC_FVNO_1) {
        type = KRB5_NT_UNKNOWN;
    } else {
        type = read(4);
    }
    length = readLength4();
    List<String> result = new ArrayList<String>();
    /*
     * DCE includes the principal's realm in the count; the new format
     * does not.
     */
    if (version == KRB5_FCC_FVNO_1)
        length--;
    for (int i = 0; i <= length; i++) {
        namelength = readLength4();
        byte[] bytes = IOUtils.readExactlyNBytes(this, namelength);
        result.add(new String(bytes));
    }
    if (result.isEmpty()) {
        throw new IOException("No realm or principal");
    }
    if (isRealm(result.get(0))) {
        realm = result.remove(0);
        if (result.isEmpty()) {
            throw new IOException("No principal name components");
        }
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                new Realm(realm));
    }
    try {
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                Realm.getDefault());
    } catch (RealmException re) {
        return null;
    }
}
 
Example 20
Source File: CCacheInputStream.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public PrincipalName readPrincipal(int version) throws IOException, RealmException {
    int type, length, namelength, kret;
    String[] pname = null;
    String realm;
    /* Read principal type */
    if (version == KRB5_FCC_FVNO_1) {
        type = KRB5_NT_UNKNOWN;
    } else {
        type = read(4);
    }
    length = readLength4();
    List<String> result = new ArrayList<String>();
    /*
     * DCE includes the principal's realm in the count; the new format
     * does not.
     */
    if (version == KRB5_FCC_FVNO_1)
        length--;
    for (int i = 0; i <= length; i++) {
        namelength = readLength4();
        byte[] bytes = IOUtils.readExactlyNBytes(this, namelength);
        result.add(new String(bytes));
    }
    if (result.isEmpty()) {
        throw new IOException("No realm or principal");
    }
    if (isRealm(result.get(0))) {
        realm = result.remove(0);
        if (result.isEmpty()) {
            throw new IOException("No principal name components");
        }
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                new Realm(realm));
    }
    try {
        return new PrincipalName(
                type,
                result.toArray(new String[result.size()]),
                Realm.getDefault());
    } catch (RealmException re) {
        return null;
    }
}