Package com.cloudhopper.commons.util

Examples of com.cloudhopper.commons.util.FastByteArrayOutputStream


            return null;
        }

        // estimate the length of the dynamic byte array
        int estimatedByteLength = estimateEncodeByteLength(str0);
        FastByteArrayOutputStream baos = new FastByteArrayOutputStream(estimatedByteLength);

        try {
            int len = str0.length();
            for (int i = 0; i < len; i++) {
                int search = 0;
                char c = str0.charAt(i);
                for (; search < CHAR_TABLE.length; search++) {
                    if (search == EXTENDED_ESCAPE) {
                        continue;
                    }

                    if (c == CHAR_TABLE[search]) {
                        baos.write(search);
                        break;
                    }

                    if (c == EXT_CHAR_TABLE[search]) {
                        baos.write(EXTENDED_ESCAPE);
                        baos.write(search);
                        break;
                    }
                }
                if (search == CHAR_TABLE.length) {
                    // A '?' character.
                    baos.write(0x3f);
                }
            }
        } catch (IOException e) {
            // should be an impossible error
            throw new RuntimeException("Impossible error with FastByteArrayOutputStream: " + e.getMessage(), e);
        }

        return baos.toByteArray();

    }
View Full Code Here


            return null;
        }

        // T-Mo-NL doesn't use multi-byte encoding, so encoded length = input length
        int estimatedByteLength = str0.length();
        FastByteArrayOutputStream baos = new FastByteArrayOutputStream(estimatedByteLength);

        try {
            int len = str0.length();
            for (int i = 0; i < len; i++) {
                int search = 0;
                char c = str0.charAt(i);

                // T-Mo-NL's one extended char is Euro mark, encoded as 0x80
                if (c == EURO_MARK)
                    baos.write(TMO_EURO_BYTE);
                else {
                    for (; search < CHAR_TABLE.length; search++) {
                        if (search == EXTENDED_ESCAPE) {
                            continue;
                        }

                        if (c == CHAR_TABLE[search]) {
                            baos.write(search);
                            break;
                        }
                    }
                    if (search == CHAR_TABLE.length) {
                        // A '?' character.
                        baos.write(0x3f);
                    }
                }
            }
        } catch (IOException e) {
            // should be an impossible error
            throw new RuntimeException("Impossible error with FastByteArrayOutputStream: " + e.getMessage(), e);
        }

        return baos.toByteArray();
    }
View Full Code Here

            return null;
        }

        // T-Mo-NL doesn't use multi-byte encoding, so encoded length = input length
        int estimatedByteLength = str0.length();
        FastByteArrayOutputStream baos = new FastByteArrayOutputStream(estimatedByteLength);

        try {
            int len = str0.length();
            for (int i = 0; i < len; i++) {
                int search = 0;
                char c = str0.charAt(i);

                // T-Mo-NL's one extended char is Euro mark, encoded as 0x80
                if (c == EURO_MARK)
                    baos.write(TMO_EURO_BYTE);
                else {
                    for (; search < CHAR_TABLE.length; search++) {
                        if (search == EXTENDED_ESCAPE) {
                            continue;
                        }

                        if (c == CHAR_TABLE[search]) {
                            baos.write(search);
                            break;
                        }
                    }
                    if (search == CHAR_TABLE.length) {
                        // A '?' character.
                        baos.write(0x3f);
                    }
                }
            }
        } catch (IOException e) {
            // should be an impossible error
            throw new RuntimeException("Impossible error with FastByteArrayOutputStream: " + e.getMessage(), e);
        }

        return baos.toByteArray();
    }
View Full Code Here

            return null;
        }

        // estimate the length of the dynamic byte array
        int estimatedByteLength = estimateEncodeByteLength(str0);
        FastByteArrayOutputStream baos = new FastByteArrayOutputStream(estimatedByteLength);

        try {
            int len = str0.length();
            for (int i = 0; i < len; i++) {
                int search = 0;
                char c = str0.charAt(i);
                for (; search < CHAR_TABLE.length; search++) {
                    if (search == EXTENDED_ESCAPE) {
                        continue;
                    }

                    if (c == CHAR_TABLE[search]) {
                        baos.write(search);
                        break;
                    }

                    if (c == EXT_CHAR_TABLE[search]) {
                        baos.write(EXTENDED_ESCAPE);
                        baos.write(search);
                        break;
                    }
                }
                if (search == CHAR_TABLE.length) {
                    // A '?' character.
                    baos.write(0x3f);
                }
            }
        } catch (IOException e) {
            // should be an impossible error
            throw new RuntimeException("Impossible error with FastByteArrayOutputStream: " + e.getMessage(), e);
        }

        return baos.toByteArray();

    }
View Full Code Here

TOP

Related Classes of com.cloudhopper.commons.util.FastByteArrayOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.