1 11 package org.eclipse.debug.ui.memory; 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 AbstractTextRendering extends AbstractTableRendering { 30 31 private String fCodePage; 32 33 38 public AbstractTextRendering(String renderingId) 39 { 40 super(renderingId); 41 } 42 43 52 public AbstractTextRendering(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 86 public String getString(String dataType, BigInteger address, MemoryByte[] data) { 87 try { 88 String paddedStr = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR); 89 if(fCodePage == null) 90 return ""; 92 boolean[] invalid = new boolean[data.length]; 93 boolean hasInvalid = false; 94 byte byteArray[] = new byte[data.length]; 95 for (int i=0; i<data.length; i++) 96 { 97 if (!data[i].isReadable()) 98 { 99 invalid[i] = true; 100 hasInvalid = true; 101 } 102 byteArray[i] = data[i].getValue(); 103 } 104 105 if (hasInvalid) 106 { 107 StringBuffer strBuf = new StringBuffer (); 108 for (int i=0; i<data.length; i++) 109 { 110 if (invalid[i]) 111 strBuf.append(paddedStr); 112 else 113 strBuf.append(new String (new byte[]{byteArray[i]}, fCodePage)); 114 } 115 return strBuf.toString(); 116 } 117 118 return new String (byteArray, fCodePage); 119 120 } catch (UnsupportedEncodingException e) { 121 return "-- error --"; } 123 } 124 125 126 129 public byte[] getBytes(String dataType, BigInteger address, MemoryByte[] currentValues, String data) { 130 try { 131 132 if (fCodePage == null) 133 return new byte[0]; 134 135 byte[] bytes = data.getBytes(fCodePage); 136 return bytes; 137 138 } catch (UnsupportedEncodingException e) { 139 return new byte[0]; 140 } 141 } 142 } 143 | Popular Tags |