java - Junit testing for base64 encoded string -


i'm trying read contents of pdf using apache's pdfbox , encode in base64 can stream elsewhere. encode use apache commons base64outputstream class. so,

bytearrayoutputstream byteoutput = new bytearrayoutputstream(); base64outputstream base64output = new base64outputstream(byteoutput); list pages = pdfdocument.getdocumentcatalog().getallpages(); iterator iter = pages.iterator(); while (iter.hasnext()) {   pdpage page = (pdpage) iter.next();   pdresources resources = page.getresources();   map<string, pdxobjectimage> pageimages = resources.getimages();   if (pageimages != null) {     iterator imageiter = pageimages.keyset().iterator();     while (imageiter.hasnext()) {       string key = (string) imageiter.next();       pdxobjectimage image = (pdxobjectimage) pageimages           .get(key);       image.write2outputstream(base64output);     }   } } string base64 = new string(byteoutput.tobytearray()); 

it seems encoding need verify writing junit test validate base64 string. following doesnt seem pass it. thoughts ?

asserttrue(content         .matches("^([a-za-z0-9+/]{4})*([a-za-z0-9+/]{4}|[a-za-z0-9+/]{3}=|[a-za-z0-9+/]{2}==)$")); 

thanks in advance

by default base64outputstream using chunk_size = 76, , chunk_separator = {'\r', '\n'}. regular expression using test if given string base64 encoded doesn't account that.

regular expression match chunked base64 (with given chunk size 64 , separator \r\n) string this:

"^(([\\w+/]{4}){19}\r\n)*(([\\w+/]{4})*([\\w+/]{4}|[\\w+/]{3}=|[\\w+/]{2}==))$" 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -