summaryrefslogtreecommitdiffstats
path: root/src/net/gcdc/asn1/uper/Document2.txt
blob: 176ec23e79257a9bcd320c74b99c0d009ca28fda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
        if (restrictionAnnotation.value() == CharacterRestriction.UTF8String) {
            // UTF8 length
            BitBuffer stringbuffer = ByteBitBuffer.createInfinite();
                 
            //char array replaced - begin
            byte[] stringasbytearray = string.getBytes(StandardCharsets.UTF_8);
            
            for (byte b: stringasbytearray){
            	UperEncoder.encodeConstrainedInt(stringbuffer, byte & 0xff, 0, 255);
            }
            //char array replaced - end
            
            stringbuffer.flip();
            if (stringbuffer.limit() % 8 != 0) { 
            		throw new AssertionError("utf8 encoding resulted not in multiple of 8 bits"); 
            }
            int numOctets = (stringbuffer.limit() + 7) / 8;  // Actually +7 is not needed here,
                                                             // since we already checked with %8.
            int position1 = bitbuffer.position();
            UperEncoder.encodeLengthDeterminant(bitbuffer, numOctets);
            UperEncoder.logger.debug(String.format("UTF8String %s,  length %d octets, encoded as %s", string, numOctets, bitbuffer.toBooleanStringFromPosition(position1)));
            int position2 = bitbuffer.position();
            for (int i = 0; i < stringbuffer.limit(); i++) {
                bitbuffer.put(stringbuffer.get());
            }
            UperEncoder.logger.debug(String.format("UTF8String %s, encoded length %d octets, value bits: %s", string, numOctets, bitbuffer.toBooleanStringFromPosition(position2)));
            return;






new String(bytearray, StandardCharsets.UTF_8));