Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 4 package com.tc.exception; 5 6 public class ExceptionWrapperImpl implements ExceptionWrapper { 7 8 private final int MAX_STAR_COUNT = 79; 9 10 public String wrap(String message) { 11 message = (message == null) ? String.valueOf(message) : message; 12 int starCount = longestLineCharCount(message); 13 if(starCount > MAX_STAR_COUNT) { 14 starCount = MAX_STAR_COUNT; 15 } 16 return "\n" + getStars(starCount) + "\n" + message 17 + "\n" + getStars(starCount) + "\n"; 18 } 19 20 private String getStars(int starCount) { 21 StringBuffer stars = new StringBuffer (); 22 while(starCount-- > 0) { 23 stars.append('*'); 24 } 25 return stars.toString(); 26 } 27 28 private int longestLineCharCount(String message) { 29 int count = 0; 30 int sidx = 0, eidx = 0; 31 while ((eidx = message.indexOf('\n', sidx)) >= 0) { 32 if (count < (eidx - sidx)) { 33 count = (eidx - sidx); 34 } 35 sidx = eidx + 1; 36 } 37 if (sidx < message.length() && count < (message.length() - sidx)) { 38 count = (message.length() - sidx); 39 } 40 return count; 41 } 42 43 } 44
| Popular Tags
|