2016-05-27 4 views
2

こんにちは、私はそれを調べましたが、誰かがJavaでRegExエラーだと言っていましたが、EnergiaがJavaを使用しているとは、 ..このエラーがなぜCコードでポップアップするのか混乱しています。Base 64非常に長い文字列をエンコードするJavaオーバーフロー、Arduino Energia IDE、TI CC3200

ERROR:

Exception in thread "Thread-5" java.lang.StackOverflowError 
    at java.util.regex.Pattern$Loop.match(Pattern.java:4295) 
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) 
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) 
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345) 
    at java.util.regex.Pattern$Branch.match(Pattern.java:4114) 
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168) 
    at java.util.regex.Pattern$Loop.match(Pattern.java:4295) 
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) 
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) 
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345) 
    at java.util.regex.Pattern$Branch.match(Pattern.java:4114) 

...、それは同じものの複数行の数百に行きます。正規表現コードとして

:この場合、私は私のイメージのセクションにハードコードされていること

注意(これはエラーの原因フィールドである)だけ試験目的のために、私は、JSONメッセージを送信しますネットワーク経由でBase64エンコーディングをWebサービスに送信し、それを画像として自分のメールに中継します。

画像の文字列を短くするとエラーは発生しませんが、実際の画像を送信するには文字列が非常に小さすぎます。本当に助けていただきありがとうございます!

// [7.12.2] Class template regex_token_iterator 
    /** 
    * Iterates over submatches in a range (or @a splits a text string). 
    * 
    * The purpose of this iterator is to enumerate all, or all specified, 
    * matches of a regular expression within a text range. The dereferenced 
    * value of an iterator of this class is a std::tr1::sub_match object. 
    */ 
    template<typename _Bi_iter, 
     typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, 
     typename _Rx_traits = regex_traits<_Ch_type> > 
    class regex_token_iterator 
    { 
    public: 
     typedef basic_regex<_Ch_type, _Rx_traits> regex_type; 
     typedef sub_match<_Bi_iter>    value_type; 
     typedef std::ptrdiff_t     difference_type; 
     typedef const value_type*     pointer; 
     typedef const value_type&     reference; 
     typedef std::forward_iterator_tag   iterator_category; 

    public: 
     /** 
     * @brief Default constructs a %regex_token_iterator. 
     * @todo Implement this function. 
     * 
     * A default-constructed %regex_token_iterator is a singular iterator 
     * that will compare equal to the one-past-the-end value for any 
     * iterator of the same type. 
     */ 
     regex_token_iterator(); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatch [IN] Which submatch to return. There are some 
     *      special values for this parameter: 
     *      - -1 each enumerated subexpression does NOT 
     *       match the regular expression (aka field 
     *       splitting) 
     *      - 0 the entire string matching the 
     *       subexpression is returned for each match 
     *       within the text. 
     *      - >0 enumerates only the indicated 
     *       subexpression from a match within the text. 
     * @param m   [IN] Policy flags for match rules. 
     * 
     * @todo Implement this function. 
     * @doctodo 
     */ 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, 
       int __submatch = 0, 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatches [IN] A list of subexpressions to return for each 
     *      regular expression match within the text. 
     * @param m   [IN] Policy flags for match rules. 
     * 
     * @todo Implement this function. 
     * @doctodo 
     */ 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 
       const regex_type& __re, 
       const std::vector<int>& __submatches, 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatches [IN] A list of subexpressions to return for each 
     *      regular expression match within the text. 
     * @param m   [IN] Policy flags for match rules. 

     * @todo Implement this function. 
     * @doctodo 
     */ 
     template<std::size_t _Nm> 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 
       const regex_type& __re, 
       const int (&__submatches)[_Nm], 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * @brief Copy constructs a %regex_token_iterator. 
     * @param rhs [IN] A %regex_token_iterator to copy. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator(const regex_token_iterator& __rhs); 

     /** 
     * @brief Assigns a %regex_token_iterator to another. 
     * @param rhs [IN] A %regex_token_iterator to copy. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator& 
     operator=(const regex_token_iterator& __rhs); 

     /** 
     * @brief Compares a %regex_token_iterator to another for equality. 
     * @todo Implement this function. 
     */ 
     bool 
     operator==(const regex_token_iterator& __rhs); 

     /** 
     * @brief Compares a %regex_token_iterator to another for inequality. 
     * @todo Implement this function. 
     */ 
     bool 
     operator!=(const regex_token_iterator& __rhs); 

     /** 
     * @brief Dereferences a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     const value_type& 
     operator*(); 

     /** 
     * @brief Selects a %regex_token_iterator member. 
     * @todo Implement this function. 
     */ 
     const value_type* 
     operator->(); 

     /** 
     * @brief Increments a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator& 
     operator++(); 

     /** 
     * @brief Postincrements a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator 
     operator++(int); 

    private: // data members for exposition only: 
     typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator; 

     position_iterator __position; 
     const value_type* __result; 
     value_type  __suffix; 
     std::size_t  __n; 
     std::vector<int> __subs; 
    }; 

    /** @brief Token iterator for C-style NULL-terminated strings. */ 
    typedef regex_token_iterator<const char*>    cregex_token_iterator; 
    /** @brief Token iterator for standard strings. */ 
    typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; 
#ifdef _GLIBCXX_USE_WCHAR_T 
    /** @brief Token iterator for C-style NULL-terminated wide strings. */ 
    typedef regex_token_iterator<const wchar_t*>   wcregex_token_iterator; 
    /** @brief Token iterator for standard wide-character strings. */ 
    typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; 
#endif 

base64.c:

#include <string.h> 

#include "base64.h" 

/* aaaack but it's fast and const should make it shared text page. */ 
static const unsigned char pr2six[256] = 
{ 
    /* ASCII table */ 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 
    64, 0, 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, 64, 64, 64, 64, 64, 
    64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 
}; 

int Base64decode_len(const char *bufcoded) 
{ 
    int nbytesdecoded; 
    register const unsigned char *bufin; 
    register int nprbytes; 

    bufin = (const unsigned char *) bufcoded; 
    while (pr2six[*(bufin++)] <= 63); 

    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; 
    nbytesdecoded = ((nprbytes + 3)/4) * 3; 

    return nbytesdecoded + 1; 
} 

int Base64decode(char *bufplain, const char *bufcoded) 
{ 
    int nbytesdecoded; 
    register const unsigned char *bufin; 
    register unsigned char *bufout; 
    register int nprbytes; 

    bufin = (const unsigned char *) bufcoded; 
    while (pr2six[*(bufin++)] <= 63); 
    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; 
    nbytesdecoded = ((nprbytes + 3)/4) * 3; 

    bufout = (unsigned char *) bufplain; 
    bufin = (const unsigned char *) bufcoded; 

    while (nprbytes > 4) { 
    *(bufout++) = 
     (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); 
    bufin += 4; 
    nprbytes -= 4; 
    } 

    /* Note: (nprbytes == 1) would be an error, so just ingore that case */ 
    if (nprbytes > 1) { 
    *(bufout++) = 
     (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); 
    } 
    if (nprbytes > 2) { 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); 
    } 
    if (nprbytes > 3) { 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); 
    } 

    *(bufout++) = '\0'; 
    nbytesdecoded -= (4 - nprbytes) & 3; 
    return nbytesdecoded; 
} 

static const char basis_64[] = 
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/"; 

int Base64encode_len(int len) 
{ 
    return ((len + 2)/3 * 4) + 1; 
} 

int Base64encode(char *encoded, const char *string, int len) 
{ 
    int i; 
    char *p; 

    p = encoded; 
    for (i = 0; i < len - 2; i += 3) { 
    *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
    *p++ = basis_64[((string[i] & 0x3) << 4) | 
        ((int) (string[i + 1] & 0xF0) >> 4)]; 
    *p++ = basis_64[((string[i + 1] & 0xF) << 2) | 
        ((int) (string[i + 2] & 0xC0) >> 6)]; 
    *p++ = basis_64[string[i + 2] & 0x3F]; 
    } 
    if (i < len) { 
    *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
    if (i == (len - 1)) { 
     *p++ = basis_64[((string[i] & 0x3) << 4)]; 
     *p++ = '='; 
    } 
    else { 
     *p++ = basis_64[((string[i] & 0x3) << 4) | 
         ((int) (string[i + 1] & 0xF0) >> 4)]; 
     *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; 
    } 
    *p++ = '='; 
    } 

    *p++ = '\0'; 
    return p - encoded; 
} 

がbase64.h:

#ifndef _BASE64_H_ 
#define _BASE64_H_ 

#ifdef __cplusplus 
extern "C" { 
#endif 

int Base64encode_len(int len); 
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src); 

int Base64decode_len(const char * coded_src); 
int Base64decode(char * plain_dst, const char *coded_src); 

#ifdef __cplusplus 
} 
#endif 

#endif //_BASE64_H_ 

さらに説明するために、私は事前にbase64エンコードしたJPEG画像を挿入しようとすると、このエラーがトリガされますテキスト...埋め込みカメラをインスタンス化しようとする前にダミーイメージを送信できることを確認したい。私はそれがbase64のコードではなく、Java Regexであると確信しています(長い文字列をトークン化し、エラーに関連していると思われます)。おそらく、それは文字列内のパターンを見つけようとしているのですが、それは非常に長いランダムな文字列なので、それを行うことはできません。

+0

エラーは実際に一致を見つけるにはあまりにも多くの「ステップ」を要する正規表現に問題があることを暗示しています。この正規表現を共有してください。 –

+0

このファイルを編集しようとするとEnergia IDEによってこのエラーがスローされますか? –

+0

あなたが共有しているコードは、「Base64encode」メソッドに役立つために必要なコードです。あなたは 'base64.h' /' base64.c'を共有できますか? – ClasG

答えて

0

Java正規表現に関連する長い文字列の解析にIDEトークンの問題があるようです。詳細については、ダイス・フォーラムに連絡してください。

関連する問題