📄 bufferimage.java
字号:
val = tab[offset++];
if(val < 0)
val += 256;
}
return res;
}
protected static void initRms()
{
synchronized(lock)
{
try
{
rs = RecordStore.openRecordStore("CacheRMS", true);
if(UtilMidp.DEBUG)
System.out.println("RMS: There are: " + rs.getNumRecords() + "records... Size:" + rs.getSize() + " Avail:" + rs.getSizeAvailable());
for(RecordEnumeration re = rs.enumerateRecords(null, null, true); re.hasNextElement();)
{
int id = re.nextRecordId();
if(UtilMidp.DEBUG)
System.out.println("Trying to read:" + id + " size:" + rs.getRecordSize(id));
byte b[] = rs.getRecord(id);
try
{
int x = getNum(b, 0, 4);
int y = getNum(b, 4, 4);
int z = getNum(b, 8, 4);
int numSat = b[12];
int size = getNum(b, 13, 2);
if(UtilMidp.DEBUG)
System.out.println("RSM, reading" + x + " " + y + " " + z + " numsat:" + numSat + " size:" + size);
BufferImage buff = new BufferImage(x, y, z, numSat, size);
buff.rmsId = id;
buff.state = 5;
if(count >= m_nbIma)
{
if(UtilMidp.DEBUG)
System.out.println("delete, count:" + count + " nbima:" + m_nbIma);
buff.delete();
} else
{
push(buff);
}
}
catch(Exception e)
{
System.out.println("ERROR: RMS initialisation, (removing it) cache:" + id);
rs.deleteRecord(id);
}
}
rs.closeRecordStore();
rs = null;
}
catch(Exception e)
{
try
{
if(rs != null)
{
System.out.println("I am closing it...");
rs.closeRecordStore();
System.out.println("Close ok...");
}
}
catch(Exception en)
{
e.printStackTrace();
}
rs = null;
System.out.println("initRMS: Exception during RMS initialisation...I am removing the RMS \n" + e);
removeRMS();
}
}
}
public static void removeRMS()
{
if(m_useRMS)
try
{
if(UtilMidp.DEBUG)
System.out.println("removing all RMS " + rs);
if(rs != null)
rs.closeRecordStore();
if(UtilMidp.DEBUG)
System.out.println("removing all RMS 1");
RecordStore.deleteRecordStore("CacheRMS");
System.out.println("remving all RMS OK");
}
catch(Exception e)
{
e.printStackTrace();
}
elemRms.setSize(0);
}
protected boolean getFromRMS()
{
try
{
// if(rmsId == -1 || ima != null)
// break MISSING_BLOCK_LABEL_335;
byte b[];
if(rs == null)
rs = RecordStore.openRecordStore("CacheRMS", true);
if(UtilMidp.DEBUG)
System.out.println("Trying to read:" + rmsId + " size:" + rs.getRecordSize(rmsId));
b = rs.getRecord(rmsId);
px = getNum(b, 0, 4);
py = getNum(b, 4, 4);
zoom = getNum(b, 8, 4);
numSat = b[12];
size = getNum(b, 13, 2);
ima = Image.createImage(b, 15, b.length - 15);
state = 3;
if(UtilMidp.DEBUG)
System.out.println("getFrom RMS: Create image:" + ima + " at pos:" + rmsId);
// return true;
rs.deleteRecord(rmsId);
state = 1;
rmsId = -1;
System.out.println("ERROR: getFromRMS: RMS initialisation, (removing it) cache:" + rmsId + " exception:");
// break MISSING_BLOCK_LABEL_335;
System.out.println("getFromRMS: Exception during RMS invalid recordid: \n" + rmsId);
rmsId = -1;
// break MISSING_BLOCK_LABEL_335;
System.out.println("getFromRMS: Exception during RMS reading...I \n");
return false;
}catch(Exception e)
{
return false;
}
}
protected void checkFile()
{
}
protected void saveOneFile()
{
}
oneElemRms findFreeRecordFor(int inSize)
{
oneElemRms res = null;
System.out.println("trying to find space for my :" + inSize);
int minSize = 0x100000;
Enumeration e = elemRms.elements();
do
{
if(!e.hasMoreElements())
break;
oneElemRms r = (oneElemRms)e.nextElement();
if(r.size > inSize && r.size < minSize)
{
minSize = r.size;
res = r;
}
} while(true);
if(res != null)
System.out.println("Found cur:" + res.id + " Size:" + res.size);
else
System.out.println("Not found...");
return res;
}
void checkUsedRms()throws Exception
{
int recordSize;
if(rs == null)
rs = RecordStore.openRecordStore("CacheRMS", true);
System.out.println("Checkd used RMS, size:" + rs.getSize());
recordSize = rs.getSize() + 32768;
int newRecordSize;
// if(recordSize <= 0x80000)
// break MISSING_BLOCK_LABEL_201;
System.out.println("Checkd used RMS, size:" + rs.getSize());
if(elemRms.size() > 0)
{
oneElemRms r = (oneElemRms)elemRms.firstElement();
System.out.println("Deleting element:" + r.id + " size:" + r.size);
rs.deleteRecord(r.id);
elemRms.removeElement(r);
} else
{
deleteLast();
}
newRecordSize = rs.getSize();
if(recordSize == newRecordSize)
{
System.out.println("Size did not changed...might be an error!");
return;
}
recordSize = newRecordSize;
exerciseRms();
// break MISSING_BLOCK_LABEL_208;
}
protected void saveOneRms()
{
try
{
if(rs == null)
rs = RecordStore.openRecordStore("CacheRMS", true);
oneElemRms r = findFreeRecordFor(buff.length);
if(r != null)
{
rs.setRecord(r.id, buff, 0, buff.length);
rmsId = r.id;
elemRms.removeElement(r);
} else
if(rs.getSizeAvailable() > buff.length + 10000)
{
rmsId = rs.addRecord(buff, 0, buff.length);
if(UtilMidp.DEBUG)
System.out.println("RMS: Save one RMS:" + rmsId);
if(UtilMidp.DEBUG)
System.out.println("--------------------------\nsaveOneRMS:!\nCurrent size:" + rs.getSize() + "\nsize avail:" + rs.getSizeAvailable() + "\n");
rs.closeRecordStore();
rs = null;
} else
{
System.out.println("saveOneRMS: not enoug space in RMS (remaining:" + rs.getSizeAvailable());
setBufferSize(m_nbIma - 1);
}
checkUsedRms();
}
catch(RecordStoreFullException e)
{
try
{
System.out.println("saveOneRMS: record store full!\nCurrent size:" + rs.getSize() + "\nsize avail:" + rs.getSizeAvailable() + "\n" + e);
}
catch(Exception e2) { }
setBufferSize(m_nbIma - 1);
}
catch(Exception e)
{
try
{
if(rs != null)
rs.closeRecordStore();
}
catch(Exception en)
{
System.out.println("Error while closing record store...");
}
rs = null;
e.printStackTrace();
}
}
protected static void writeInt(ByteArrayOutputStream bo, int val, int length)
{
while(length-- > 0)
bo.write(val >> length * 8 & 0xff);
}
protected void ImagecreateImage(InputStream is, int size)
{
buff = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
writeInt(bo, px, 4);
writeInt(bo, py, 4);
writeInt(bo, zoom, 4);
bo.write(numSat);
writeInt(bo, size, 2);
try
{
if(UtilMidp.DEBUG)
System.out.println("Start loading...");
do
{
int c = is.read();
if(c == -1)
break;
m_dataDownloadCounter++;
bo.write(c);
} while(--size != 0);
if(UtilMidp.DEBUG)
System.out.println("loading ok2...");
buff = bo.toByteArray();
if(UtilMidp.DEBUG)
System.out.println("loading ok2.1...");
byte tmp[] = new byte[buff.length - 15];
System.arraycopy(buff, 15, tmp, 0, tmp.length);
if(UtilMidp.DEBUG)
System.out.println("array copy ok..." + tmp.length + " ");
ima = Image.createImage(tmp, 0, tmp.length);
if(UtilMidp.DEBUG)
System.out.println("loading ok3...");
if(UtilMidp.m_isFileAPIEnabled && m_useFileAPI)
saveOneFile();
if(!m_useRMS)
{
if(UtilMidp.DEBUG)
System.out.println("Je met buff a null");
buff = null;
} else
{
if(UtilMidp.DEBUG)
System.out.println("Image loading ok....");
saveOneRms();
buff = null;
}
}
catch(IOException e)
{
System.out.println("Switching to proxy download....");
m_useProxy = true;
}
catch(Exception e)
{
System.out.println("EXCEPTION in CreateImage...");
e.printStackTrace();
buff = null;
System.out.println("CA MERDE... length:" + buff.length);
}
}
public static void reset()
{
while(deleteLast()) ;
}
public static boolean checkBuffer()
{
boolean loaded = false;
int nbVis = 0;
int maxCount = 0x186a0;
int pos = -1;
int d = 0;
BufferImage ima = first;
BufferImage prev = null;
rootTiles.removeAllElements();
try
{
do
{
if(ima == null)
break;
if(ima.ima == null && ima.state == 1 && !loaded)
try
{
if(UtilMidp.m_isFileAPIEnabled && m_useFileAPI)
ima.checkFile();
if(ima.state == 1)
if(m_modePacked)
{
rootTiles.addElement(ima);
} else
{
ima.fetchImage();
loaded = true;
}
}
catch(OutOfMemoryError e)
{
Alert a = new Alert("ERROR", "You are running out of memory. Reduce the cache size...", null, AlertType.ERROR);
System.gc();
}
catch(Exception e)
{
Alert a = new Alert("ERROR", "Critic error. Please report it to thomas.landspurg@gmail.com. \n\nError:" + e, null, AlertType.ERROR);
a.setTimeout(-2);
e.printStackTrace();
}
else
if(ima.state == 6)
synchronized(lock)
{
if(prev != null)
prev.next = ima.next;
else
first = ima.next;
count--;
ima.delete();
ima = prev;
}
else
if(ima.ima != null)
nbVis++;
synchronized(lock)
{
if(ima != null)
{
prev = ima;
ima = ima.next;
}
}
if(++d > 1000)
{
System.out.println("Error in get Image");
dumpState();
}
} while(true);
if(rootTiles.size() > 0)
fetcher(rootTiles);
if(nbVis > m_nbImaVis)
{
ima = first;
BufferImage lastImaVis = null;
synchronized(lock)
{
for(; ima != null; ima = ima.next)
if(ima.state == 3)
lastImaVis = ima;
if(lastImaVis != null)
{
remove(lastImaVis);
if(lastImaVis.rmsId != -1)
{
lastImaVis.ima = null;
lastImaVis.state = 5;
} else
{
lastImaVis.delete();
}
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return loaded;
}
private static Image getDefaultImage(int code, int size)
{
if(defaultIma == null)
{
defaultIma = Image.createImage(1, 1);
return defaultIma;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -