1 11 package org.eclipse.debug.internal.ui.memory.provisional; 12 13 import java.io.UnsupportedEncodingException ; 14 import java.math.BigInteger ; 15 16 import org.eclipse.debug.core.model.MemoryByte; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.ui.IDebugUIConstants; 19 20 29 abstract public class AbstractAsyncTextRendering extends AbstractAsyncTableRendering { 30 31 private String fCodePage; 32 33 38 public AbstractAsyncTextRendering(String renderingId) 39 { 40 super(renderingId); 41 } 42 43 52 public AbstractAsyncTextRendering(String renderingId, String codePage) 53 { 54 super(renderingId); 55 fCodePage = codePage; 56 } 57 58 67 public void setCodePage(String codePage) 68 { 69 fCodePage = codePage; 70 } 71 72 78 public String getCodePage() 79 { 80 return fCodePage; 81 } 82 83 84 87 public String getString(String dataType, BigInteger address, MemoryByte[] data) { 88 try { 89 String paddedStr = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR); 90 if(fCodePage == null) 91 return ""; 93 boolean[] invalid = new boolean[data.length]; 94 boolean hasInvalid = false; 95 byte byteArray[] = new byte[data.length]; 96 for (int i=0; i<data.length; i++) 97 { 98 if (!data[i].isReadable()) 99 { 100 invalid[i] = true; 101 hasInvalid = true; 102 } 103 byteArray[i] = data[i].getValue(); 104 } 105 106 if (hasInvalid) 107 { 108 StringBuffer strBuf = new StringBuffer (); 109 for (int i=0; i<data.length; i++) 110 { 111 if (invalid[i]) 112 strBuf.append(paddedStr); 113 else 114 strBuf.append(new String (new byte[]{byteArray[i]}, fCodePage)); 115 } 116 return strBuf.toString(); 117 } 118 119 return new String (byteArray, fCodePage); 120 121 } catch (UnsupportedEncodingException e) { 122 return "-- error --"; } 124 } 125 126 127 130 public byte[] getBytes(String dataType, BigInteger address, MemoryByte[] currentValues, String data) { 131 try { 132 133 if (fCodePage == null) 134 return new byte[0]; 135 136 byte[] bytes = data.getBytes(fCodePage); 137 return bytes; 138 139 } catch (UnsupportedEncodingException e) { 140 return new byte[0]; 141 } 142 } 143 } 144 | Popular Tags |