Java Code Examples for java.util.Vector#copyInto()

The following examples show how to use java.util.Vector#copyInto() . 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: RE.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an array of Strings, whose toString representation matches a regular
 * expression. This method works like the Perl function of the same name.  Given
 * a regular expression of "a*b" and an array of String objects of [foo, aab, zzz,
 * aaaab], the array of Strings returned by grep would be [aab, aaaab].
 *
 * @param search Array of Objects to search
 * @return Array of Strings whose toString() value matches this regular expression.
 */
public String[] grep(Object[] search)
{
    // Create new vector to hold return items
    Vector v = new Vector();

    // Traverse array of objects
    for (int i = 0; i < search.length; i++)
    {
        // Get next object as a string
        String s = search[i].toString();

        // If it matches this regexp, add it to the list
        if (match(s))
        {
            v.addElement(s);
        }
    }

    // Return vector as an array of strings
    String[] ret = new String[v.size()];
    v.copyInto(ret);
    return ret;
}
 
Example 2
Source File: MimeHeaders.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns all of the values for the specified header as an array of
 * <code>String</code> objects.
 *
 * @param   name the name of the header for which values will be returned
 * @return a <code>String</code> array with all of the values for the
 *         specified header
 * @see #setHeader
 */
public String[] getHeader(String name) {
    Vector values = new Vector();

    for(int i = 0; i < headers.size(); i++) {
        MimeHeader hdr = (MimeHeader) headers.elementAt(i);
        if (hdr.getName().equalsIgnoreCase(name)
            && hdr.getValue() != null)
            values.addElement(hdr.getValue());
    }

    if (values.size() == 0)
        return null;

    String r[] = new String[values.size()];
    values.copyInto(r);
    return r;
}
 
Example 3
Source File: ZoneView.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Break up the zone at the given index into pieces
 * of an acceptable size.
 */
void splitZone(int index, int offs0, int offs1) {
    // divide the old zone into a new set of bins
    Element elem = getElement();
    Document doc = elem.getDocument();
    Vector<View> zones = new Vector<View>();
    int offs = offs0;
    do {
        offs0 = offs;
        offs = Math.min(getDesiredZoneEnd(offs0), offs1);
        zones.addElement(createZone(offs0, offs));
    } while (offs < offs1);
    View oldZone = getView(index);
    View[] newZones = new View[zones.size()];
    zones.copyInto(newZones);
    replace(index, 1, newZones);
}
 
Example 4
Source File: AuthorizationData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new <code>AuthorizationData,</code> instance.
 * @param der a single DER-encoded value.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public AuthorizationData(DerValue der) throws Asn1Exception, IOException {
    Vector<AuthorizationDataEntry> v = new Vector<>();
    if (der.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    while (der.getData().available() > 0) {
        v.addElement(new AuthorizationDataEntry(der.getData().getDerValue()));
    }
    if (v.size() > 0) {
        entry = new AuthorizationDataEntry[v.size()];
        v.copyInto(entry);
    }
}
 
Example 5
Source File: ClassBrowser.java    From beanshell with Apache License 2.0 5 votes vote down vote up
Method [] getPublicMethods( Method [] methods ) {
    Vector v = new Vector();
    for(int i=0; i< methods.length; i++)
        if ( Modifier.isPublic(methods[i].getModifiers()) )
            v.addElement( methods[i] );

    Method [] ma = new Method [ v.size() ];
    v.copyInto( ma );
    return ma;
}
 
Example 6
Source File: KrbCredInfo.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes an KrbCredInfo object.
 * @return the byte array of encoded KrbCredInfo object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    Vector<DerValue> v = new Vector<>();
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode()));
    if (pname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), pname.getRealm().asn1Encode()));
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode()));
    }
    if (flags != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode()));
    if (authtime != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authtime.asn1Encode()));
    if (starttime != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), starttime.asn1Encode()));
    if (endtime != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode()));
    if (renewTill != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode()));
    if (sname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), sname.getRealm().asn1Encode()));
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode()));
    }
    if (caddr != null)
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode()));
    DerValue der[] = new DerValue[v.size()];
    v.copyInto(der);
    DerOutputStream out = new DerOutputStream();
    out.putSequence(der);
    return out.toByteArray();
}
 
Example 7
Source File: mySSLSession.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public String[] getValueNames() {
    Vector vector = new Vector();
    Enumeration enumeration = table.keys();
    while (enumeration.hasMoreElements()) {
        vector.addElement(enumeration.nextElement());
    }
    String as[] = new String[vector.size()];
    vector.copyInto(as);
    return as;
}
 
Example 8
Source File: Authenticator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes an Authenticator object.
 * @return byte array of encoded Authenticator object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    Vector<DerValue> v = new Vector<>();
    DerOutputStream temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(authenticator_vno));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray()));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), cname.getRealm().asn1Encode()));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode()));
    if (cksum != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode()));
    }
    temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(cusec));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), temp.toByteArray()));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), ctime.asn1Encode()));
    if (subKey != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), subKey.asn1Encode()));
    }
    if (seqNumber != null) {
        temp = new DerOutputStream();
        // encode as an unsigned integer (UInt32)
        temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), temp.toByteArray()));
    }
    if (authorizationData != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), authorizationData.asn1Encode()));
    }
    DerValue der[] = new DerValue[v.size()];
    v.copyInto(der);
    temp = new DerOutputStream();
    temp.putSequence(der);
    DerOutputStream out = new DerOutputStream();
    out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x02), temp);
    return out.toByteArray();
}
 
Example 9
Source File: CSS.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of all the strings in <code>value</code>
 *         that are separated by whitespace.
 */
static String[] parseStrings(String value) {
    int         current, last;
    int         length = (value == null) ? 0 : value.length();
    Vector<String> temp = new Vector<String>(4);

    current = 0;
    while (current < length) {
        // Skip ws
        while (current < length && Character.isWhitespace
               (value.charAt(current))) {
            current++;
        }
        last = current;
        while (current < length && !Character.isWhitespace
               (value.charAt(current))) {
            current++;
        }
        if (last != current) {
            temp.addElement(value.substring(last, current));
        }
        current++;
    }
    String[] retValue = new String[temp.size()];
    temp.copyInto(retValue);
    return retValue;
}
 
Example 10
Source File: RTCPTransmitter.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
protected RTCPReportBlock[] makerecreports(long l)
{
    Vector vector = new Vector();
    for(Enumeration enumeration = cache.cache.elements(); enumeration.hasMoreElements();)
    {
        SSRCInfo ssrcinfo = (SSRCInfo)enumeration.nextElement();
        if(!ssrcinfo.ours && ssrcinfo.sender)
        {
            RTCPReportBlock rtcpreportblock = new RTCPReportBlock();
            rtcpreportblock.ssrc = ssrcinfo.ssrc;
            rtcpreportblock.lastseq = ssrcinfo.maxseq + ssrcinfo.cycles;
            rtcpreportblock.jitter = (int)ssrcinfo.jitter;
            rtcpreportblock.lsr = (int)(ssrcinfo.lastSRntptimestamp >> 32);
            rtcpreportblock.dlsr = (int)((double)(l - ssrcinfo.lastSRreceiptTime) * 65.536000000000001D);
            rtcpreportblock.packetslost = (int)(((rtcpreportblock.lastseq - (long)ssrcinfo.baseseq) + 1L) - (long)ssrcinfo.received);
            if(rtcpreportblock.packetslost < 0)
            {
                rtcpreportblock.packetslost = 0;
            }
            double d = (double)(rtcpreportblock.packetslost - ssrcinfo.prevlost) / (double)(rtcpreportblock.lastseq - (long)ssrcinfo.prevmaxseq);
            if(d < 0.0D)
            {
                d = 0.0D;
            }
            rtcpreportblock.fractionlost = (int)(d * 256D);
            ssrcinfo.prevmaxseq = (int)rtcpreportblock.lastseq;
            ssrcinfo.prevlost = rtcpreportblock.packetslost;
            vector.addElement(rtcpreportblock);
        }
    }

    RTCPReportBlock artcpreportblock[] = new RTCPReportBlock[vector.size()];
    vector.copyInto(artcpreportblock);
    return artcpreportblock;
}
 
Example 11
Source File: JTextComponent.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public KeyStroke[] getKeyStrokesForAction(Action a) {
    if (a == null) {
        return null;
    }
    KeyStroke[] retValue = null;
    // Determine local bindings first.
    Vector<KeyStroke> keyStrokes = null;
    for (Enumeration<KeyStroke> keys = bindings.keys(); keys.hasMoreElements();) {
        KeyStroke key = keys.nextElement();
        if (bindings.get(key) == a) {
            if (keyStrokes == null) {
                keyStrokes = new Vector<KeyStroke>();
            }
            keyStrokes.addElement(key);
        }
    }
    // See if the parent has any.
    if (parent != null) {
        KeyStroke[] pStrokes = parent.getKeyStrokesForAction(a);
        if (pStrokes != null) {
            // Remove any bindings defined in the parent that
            // are locally defined.
            int rCount = 0;
            for (int counter = pStrokes.length - 1; counter >= 0;
                 counter--) {
                if (isLocallyDefined(pStrokes[counter])) {
                    pStrokes[counter] = null;
                    rCount++;
                }
            }
            if (rCount > 0 && rCount < pStrokes.length) {
                if (keyStrokes == null) {
                    keyStrokes = new Vector<KeyStroke>();
                }
                for (int counter = pStrokes.length - 1; counter >= 0;
                     counter--) {
                    if (pStrokes[counter] != null) {
                        keyStrokes.addElement(pStrokes[counter]);
                    }
                }
            }
            else if (rCount == 0) {
                if (keyStrokes == null) {
                    retValue = pStrokes;
                }
                else {
                    retValue = new KeyStroke[keyStrokes.size() +
                                            pStrokes.length];
                    keyStrokes.copyInto(retValue);
                    System.arraycopy(pStrokes, 0, retValue,
                                keyStrokes.size(), pStrokes.length);
                    keyStrokes = null;
                }
            }
        }
    }
    if (keyStrokes != null) {
        retValue = new KeyStroke[keyStrokes.size()];
        keyStrokes.copyInto(retValue);
    }
    return retValue;
}
 
Example 12
Source File: PrincipalName.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static String[] parseName(String name) {

        Vector<String> tempStrings = new Vector<>();
        String temp = name;
        int i = 0;
        int componentStart = 0;
        String component;

        while (i < temp.length()) {
            if (temp.charAt(i) == NAME_COMPONENT_SEPARATOR) {
                /*
                 * If this separator is escaped then don't treat it
                 * as a separator
                 */
                if (i > 0 && temp.charAt(i - 1) == '\\') {
                    temp = temp.substring(0, i - 1) +
                        temp.substring(i, temp.length());
                    continue;
                }
                else {
                    if (componentStart <= i) {
                        component = temp.substring(componentStart, i);
                        tempStrings.addElement(component);
                    }
                    componentStart = i + 1;
                }
            } else {
                if (temp.charAt(i) == NAME_REALM_SEPARATOR) {
                    /*
                     * If this separator is escaped then don't treat it
                     * as a separator
                     */
                    if (i > 0 && temp.charAt(i - 1) == '\\') {
                        temp = temp.substring(0, i - 1) +
                            temp.substring(i, temp.length());
                        continue;
                    } else {
                        if (componentStart < i) {
                            component = temp.substring(componentStart, i);
                            tempStrings.addElement(component);
                        }
                        componentStart = i + 1;
                        break;
                    }
                }
            }
            i++;
        }

        if (i == temp.length()) {
            component = temp.substring(componentStart, i);
            tempStrings.addElement(component);
        }

        String[] result = new String[tempStrings.size()];
        tempStrings.copyInto(result);
        return result;
    }
 
Example 13
Source File: RTCPTransmitter.java    From mts with GNU General Public License v3.0 4 votes vote down vote up
protected Vector makereports()
{
    Vector vector = new Vector();
    SSRCInfo ssrcinfo = ssrcInfo;
    boolean flag = false;
    if(ssrcinfo.sender)
    {
        flag = true;
    }
    long l = System.currentTimeMillis();
    RTCPReportBlock artcpreportblock[] = makerecreports(l);
    RTCPReportBlock artcpreportblock1[] = artcpreportblock;
    if(artcpreportblock.length > 31)
    {
        artcpreportblock1 = new RTCPReportBlock[31];
        System.arraycopy(artcpreportblock, 0, artcpreportblock1, 0, 31);
    }
    if(flag)
    {
        RTCPSRPacket rtcpsrpacket = new RTCPSRPacket(ssrcinfo.ssrc, artcpreportblock1);
        vector.addElement(rtcpsrpacket);
        long l1 = ssrcinfo.systime == 0L ? System.currentTimeMillis() : ssrcinfo.systime;
        long l2 = l1 / 1000L;
        double d = (double)(l1 - l2 * 1000L) / 1000D;
        rtcpsrpacket.ntptimestamplsw = (int)(d * 4294967296D);
        rtcpsrpacket.ntptimestampmsw = l2;
        rtcpsrpacket.rtptimestamp = (int)ssrcinfo.rtptime;
        rtcpsrpacket.packetcount = ssrcinfo.maxseq - ssrcinfo.baseseq;
        rtcpsrpacket.octetcount = ssrcinfo.bytesreceived;
    } else
    {
        RTCPRRPacket rtcprrpacket = new RTCPRRPacket(ssrcinfo.ssrc, artcpreportblock1);
        vector.addElement(rtcprrpacket);
    }
    if(artcpreportblock1 != artcpreportblock)
    {
        for(int i = 31; i < artcpreportblock.length; i += 31)
        {
            if(artcpreportblock.length - i < 31)
            {
                artcpreportblock1 = new RTCPReportBlock[artcpreportblock.length - i];
            }
            System.arraycopy(artcpreportblock, i, artcpreportblock1, 0, artcpreportblock1.length);
            RTCPRRPacket rtcprrpacket1 = new RTCPRRPacket(ssrcinfo.ssrc, artcpreportblock1);
            vector.addElement(rtcprrpacket1);
        }

    }
    RTCPSDESPacket rtcpsdespacket = new RTCPSDESPacket(new RTCPSDES[1]);
    rtcpsdespacket.sdes[0] = new RTCPSDES();
    rtcpsdespacket.sdes[0].ssrc = ssrcInfo.ssrc;
    Vector vector1 = new Vector();
    vector1.addElement(new RTCPSDESItem(1, ssrcinfo.sourceInfo.getCNAME()));
    if(sdescounter % 3 == 0)
    {
        if(ssrcinfo.name != null && ssrcinfo.name.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(2, ssrcinfo.name.getDescription()));
        }
        if(ssrcinfo.email != null && ssrcinfo.email.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(3, ssrcinfo.email.getDescription()));
        }
        if(ssrcinfo.phone != null && ssrcinfo.phone.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(4, ssrcinfo.phone.getDescription()));
        }
        if(ssrcinfo.loc != null && ssrcinfo.loc.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(5, ssrcinfo.loc.getDescription()));
        }
        if(ssrcinfo.tool != null && ssrcinfo.tool.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(6, ssrcinfo.tool.getDescription()));
        }
        if(ssrcinfo.note != null && ssrcinfo.note.getDescription() != null)
        {
            vector1.addElement(new RTCPSDESItem(7, ssrcinfo.note.getDescription()));
        }
    }
    sdescounter++;
    rtcpsdespacket.sdes[0].items = new RTCPSDESItem[vector1.size()];
    vector1.copyInto(rtcpsdespacket.sdes[0].items);
    vector.addElement(rtcpsdespacket);

    return vector;
}
 
Example 14
Source File: StubGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Collect all the inherited remote interfaces.
 */
Type[] collectAllRemoteInterfaces (CompoundType theType) {
    Vector list = new Vector();

    // Collect up all the Remote interfaces, and get an instance
    // for java.rmi.Remote...

    addRemoteInterfaces(list,theType);

    // Create and return our results...

    Type[] result = new Type[list.size()];
    list.copyInto(result);

    return result;
}
 
Example 15
Source File: CryptoPolicyParser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * parse a CryptoPermission entry
 */
private CryptoPermissionEntry parsePermissionEntry(
        Hashtable<String, Vector<String>> processedPermissions)
    throws ParsingException, IOException
{
    CryptoPermissionEntry e = new CryptoPermissionEntry();

    match("Permission");
    e.cryptoPermission = match("permission type");

    if (e.cryptoPermission.equals("javax.crypto.CryptoAllPermission")) {
        // Done with the CryptoAllPermission entry.
        e.alg = CryptoAllPermission.ALG_NAME;
        e.maxKeySize = Integer.MAX_VALUE;
        return e;
    }

    // Should see the algorithm name.
    if (peek("\"")) {
        // Algorithm name - always convert to upper case after parsing.
        e.alg = match("quoted string").toUpperCase(ENGLISH);
    } else {
        // The algorithm name can be a wildcard.
        if (peek("*")) {
            match("*");
            e.alg = CryptoPermission.ALG_NAME_WILDCARD;
        } else {
            throw new ParsingException(st.lineno(),
                                       "Missing the algorithm name");
        }
    }

    peekAndMatch(",");

    // May see the exemption mechanism name.
    if (peek("\"")) {
        // Exemption mechanism name - convert to upper case too.
        e.exemptionMechanism = match("quoted string").toUpperCase(ENGLISH);
    }

    peekAndMatch(",");

    // Check whether this entry is consistent with other permission entries
    // that have been read.
    if (!isConsistent(e.alg, e.exemptionMechanism, processedPermissions)) {
        throw new ParsingException(st.lineno(), "Inconsistent policy");
    }

    // Should see the maxKeySize if not at the end of this entry yet.
    if (peek("number")) {
        e.maxKeySize = match();
    } else {
        if (peek("*")) {
            match("*");
            e.maxKeySize = Integer.MAX_VALUE;
        } else {
            if (!peek(";")) {
                throw new ParsingException(st.lineno(),
                                           "Missing the maximum " +
                                           "allowable key size");
            } else {
                // At the end of this permission entry
                e.maxKeySize = Integer.MAX_VALUE;
            }
        }
    }

    peekAndMatch(",");

    // May see an AlgorithmParameterSpec class name.
    if (peek("\"")) {
        // AlgorithmParameterSpec class name.
        String algParamSpecClassName = match("quoted string");

        Vector<Integer> paramsV = new Vector<>(1);
        while (peek(",")) {
            match(",");
            if (peek("number")) {
                paramsV.addElement(new Integer(match()));
            } else {
                if (peek("*")) {
                    match("*");
                    paramsV.addElement(new Integer(Integer.MAX_VALUE));
                } else {
                    throw new ParsingException(st.lineno(),
                                               "Expecting an integer");
                }
            }
        }

        Integer[] params = new Integer[paramsV.size()];
        paramsV.copyInto(params);

        e.checkParam = true;
        e.algParamSpec = getInstance(algParamSpecClassName, params);
    }

    return e;
}
 
Example 16
Source File: SQLValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }

  // See which backgrounds to color...
  //
  if ( scriptStatements != null ) {
    for ( SqlScriptStatement statement : scriptStatements ) {
      // Leave non-executed statements alone.
      //
      StyleRange styleRange = new StyleRange();
      styleRange.start = statement.getFromIndex();
      styleRange.length = statement.getToIndex() - statement.getFromIndex();

      if ( statement.isComplete() ) {
        if ( statement.isOk() ) {
          // GUIResource.getInstance().getColor(63, 127, 95), // green

          styleRange.background = GUIResource.getInstance().getColor( 244, 238, 224 ); // honey dew
        } else {
          styleRange.background = GUIResource.getInstance().getColor( 250, 235, 215 ); // Antique White
        }
      } else {
        styleRange.background = GUIResource.getInstance().getColorWhite();
      }

      styles.add( styleRange );
    }
  }

  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example 17
Source File: KDCReqBody.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return an byte array of encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode(int msgType) throws Asn1Exception, IOException {
    Vector<DerValue> v = new Vector<>();
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), kdcOptions.asn1Encode()));
    if (msgType == Krb5.KRB_AS_REQ) {
        if (cname != null) {
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), cname.asn1Encode()));
        }
    }
    if (sname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.getRealm().asn1Encode()));
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), sname.asn1Encode()));
    } else if (cname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cname.getRealm().asn1Encode()));
    }
    if (from != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), from.asn1Encode()));
    }
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), till.asn1Encode()));
    if (rtime != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), rtime.asn1Encode()));
    }
    DerOutputStream temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(nonce));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), temp.toByteArray()));
    //revisit, if empty eType sequences are allowed
    temp = new DerOutputStream();
    for (int i = 0; i < eType.length; i++) {
        temp.putInteger(BigInteger.valueOf(eType[i]));
    }
    DerOutputStream eTypetemp = new DerOutputStream();
    eTypetemp.write(DerValue.tag_SequenceOf, temp);
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), eTypetemp.toByteArray()));
    if (addresses != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), addresses.asn1Encode()));
    }
    if (encAuthorizationData != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), encAuthorizationData.asn1Encode()));
    }
    if (additionalTickets != null && additionalTickets.length > 0) {
        temp = new DerOutputStream();
        for (int i = 0; i < additionalTickets.length; i++) {
            temp.write(additionalTickets[i].asn1Encode());
        }
        DerOutputStream ticketsTemp = new DerOutputStream();
        ticketsTemp.write(DerValue.tag_SequenceOf, temp);
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), ticketsTemp.toByteArray()));
    }
    DerValue der[] = new DerValue[v.size()];
    v.copyInto(der);
    temp = new DerOutputStream();
    temp.putSequence(der);
    return temp.toByteArray();
}
 
Example 18
Source File: KDCReqBody.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a KDCReqBody object.
 * @param encoding a DER-encoded data.
 * @param msgType an int indicating whether it's KRB_AS_REQ or KRB_TGS_REQ type.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while constructing a Realm object from the encoded data.
 *
 */
public KDCReqBody(DerValue encoding, int msgType)
        throws Asn1Exception, RealmException, KrbException, IOException {
    DerValue der, subDer;
    addresses = null;
    encAuthorizationData = null;
    additionalTickets = null;
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    kdcOptions = KDCOptions.parse(encoding.getData(), (byte)0x00, false);

    // cname only appears in AS-REQ and it shares the realm field with
    // sname. This is the only place where realm comes after the name.
    // We first give cname a fake realm and reassign it the correct
    // realm after the realm field is read.
    cname = PrincipalName.parse(encoding.getData(), (byte)0x01, true,
            new Realm("PLACEHOLDER"));
    if ((msgType != Krb5.KRB_AS_REQ) && (cname != null)) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    Realm realm = Realm.parse(encoding.getData(), (byte)0x02, false);
    if (cname != null) {
        cname = new PrincipalName(
                cname.getNameType(), cname.getNameStrings(), realm);
    }
    sname = PrincipalName.parse(encoding.getData(), (byte)0x03, true, realm);
    from = KerberosTime.parse(encoding.getData(), (byte)0x04, true);
    till = KerberosTime.parse(encoding.getData(), (byte)0x05, false);
    rtime = KerberosTime.parse(encoding.getData(), (byte)0x06, true);
    der = encoding.getData().getDerValue();
    if ((der.getTag() & (byte)0x1F) == (byte)0x07) {
        nonce = der.getData().getBigInteger().intValue();
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    der = encoding.getData().getDerValue();
    Vector<Integer> v = new Vector<>();
    if ((der.getTag() & (byte)0x1F) == (byte)0x08) {
        subDer = der.getData().getDerValue();

        if (subDer.getTag() == DerValue.tag_SequenceOf) {
            while(subDer.getData().available() > 0) {
                v.addElement(subDer.getData().getBigInteger().intValue());
            }
            eType = new int[v.size()];
            for (int i = 0; i < v.size(); i++) {
                eType[i] = v.elementAt(i);
            }
        } else {
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    if (encoding.getData().available() > 0) {
        addresses = HostAddresses.parse(encoding.getData(), (byte)0x09, true);
    }
    if (encoding.getData().available() > 0) {
        encAuthorizationData = EncryptedData.parse(encoding.getData(), (byte)0x0A, true);
    }
    if (encoding.getData().available() > 0) {
        Vector<Ticket> tempTickets = new Vector<>();
        der = encoding.getData().getDerValue();
        if ((der.getTag() & (byte)0x1F) == (byte)0x0B) {
            subDer = der.getData().getDerValue();
            if (subDer.getTag() == DerValue.tag_SequenceOf) {
                while (subDer.getData().available() > 0) {
                    tempTickets.addElement(new Ticket(subDer.getData().getDerValue()));
                }
            } else {
                throw new Asn1Exception(Krb5.ASN1_BAD_ID);
            }
            if (tempTickets.size() > 0) {
                additionalTickets = new Ticket[tempTickets.size()];
                tempTickets.copyInto(additionalTickets);
            }
        } else {
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
        }
    }
    if (encoding.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
 
Example 19
Source File: KDCReqBody.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return an byte array of encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode(int msgType) throws Asn1Exception, IOException {
    Vector<DerValue> v = new Vector<>();
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), kdcOptions.asn1Encode()));
    if (msgType == Krb5.KRB_AS_REQ) {
        if (cname != null) {
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), cname.asn1Encode()));
        }
    }
    if (sname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.getRealm().asn1Encode()));
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), sname.asn1Encode()));
    } else if (cname != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cname.getRealm().asn1Encode()));
    }
    if (from != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), from.asn1Encode()));
    }
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), till.asn1Encode()));
    if (rtime != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), rtime.asn1Encode()));
    }
    DerOutputStream temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(nonce));
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), temp.toByteArray()));
    //revisit, if empty eType sequences are allowed
    temp = new DerOutputStream();
    for (int i = 0; i < eType.length; i++) {
        temp.putInteger(BigInteger.valueOf(eType[i]));
    }
    DerOutputStream eTypetemp = new DerOutputStream();
    eTypetemp.write(DerValue.tag_SequenceOf, temp);
    v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), eTypetemp.toByteArray()));
    if (addresses != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), addresses.asn1Encode()));
    }
    if (encAuthorizationData != null) {
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), encAuthorizationData.asn1Encode()));
    }
    if (additionalTickets != null && additionalTickets.length > 0) {
        temp = new DerOutputStream();
        for (int i = 0; i < additionalTickets.length; i++) {
            temp.write(additionalTickets[i].asn1Encode());
        }
        DerOutputStream ticketsTemp = new DerOutputStream();
        ticketsTemp.write(DerValue.tag_SequenceOf, temp);
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), ticketsTemp.toByteArray()));
    }
    DerValue der[] = new DerValue[v.size()];
    v.copyInto(der);
    temp = new DerOutputStream();
    temp.putSequence(der);
    return temp.toByteArray();
}
 
Example 20
Source File: KRBCred.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes an KRBCred object.
 * @param encoding a single DER-encoded value.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception KrbApErrException if the value read from the DER-encoded data
 *  stream does not match the pre-defined value.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
private void init(DerValue encoding) throws Asn1Exception,
        RealmException, KrbApErrException, IOException {
    if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x16)
            || (encoding.isApplication() != true)
            || (encoding.isConstructed() != true)) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue der, subDer;
    der = encoding.getData().getDerValue();
    if (der.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x00) {
        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_CRED) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x02) {
        DerValue subsubDer = subDer.getData().getDerValue();
        if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
        }
        Vector<Ticket> v = new Vector<>();
        while (subsubDer.getData().available() > 0) {
            v.addElement(new Ticket(subsubDer.getData().getDerValue()));
        }
        if (v.size() > 0) {
            tickets = new Ticket[v.size()];
            v.copyInto(tickets);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false);

    if (der.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}