本文整理汇总了Java中javax.microedition.rms.RecordStoreException类的典型用法代码示例。如果您正苦于以下问题:Java RecordStoreException类的具体用法?Java RecordStoreException怎么用?Java RecordStoreException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RecordStoreException类属于javax.microedition.rms包,在下文中一共展示了RecordStoreException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFreeBlockAt1
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testFreeBlockAt1() throws RecordStoreException {
final INorFlashSectorState sector = mock(INorFlashSectorState.class);
final Address address = Address.fromPrimitive(12);
final INorFlashSectorStateList inUseList = mock(INorFlashSectorStateList.class);
final INorFlashSectorStateList toBeErasedList = mock(INorFlashSectorStateList.class);
castHeap.sectorStates = new INorFlashSectorState[] {sector};
castHeap.inUseSectorStateList = inUseList;
castHeap.toBeErasedSectorStateList = toBeErasedList;
castHeap.hasScannedBlocks = true;
expects(new InAnyOrder() {{
allowing(sector).getStartAddress();will(returnValue(Address.zero()));
allowing(sector).getEndAddress();will(returnValue(Address.zero().add(1024)));
one(sector).writeBytes(with(equal(address.toUWord().toInt() + NorFlashMemoryHeap.BLOCK_HEADER_SIZE - 2)), with(an(byte[].class)), with(equal(0)), with(equal(2)));
one(sector).decrementMallocedCount();
one(sector).incrementFreedBlockCount();
one(sector).getOwningList();will(returnValue(castHeap.toBeErasedSectorStateList));
}});
heap.freeBlockAt(address);
}
示例2: testGetRecordBuffered
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testGetRecordBuffered() throws RecordStoreException, IOException {
final int recordId = 1;
final Address address = Address.fromPrimitive(10);
castStore.recordIds = new int[] {recordId};
castStore.recordAddresses = new Address[] {address};
castStore.numRecords = castStore.recordIds.length;
final IRecordEntry record = mock(IRecordEntry.class);
final byte[] bytes = new byte[0];
final int bytesOffset = 5;
expects(new InThisOrder() {{
one(manager).getEntryAt(address);will(returnValue(record));
one(record).getBytesLength();will(returnValue(0));
one(record).getBytes(bytes, bytesOffset, 0);
}});
store.getRecord(recordId, bytes, bytesOffset);
}
示例3: logEntry
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
/**
* Write the RmsEntry type byte, RmsEntry data, and optional pad byte.
*
* @param entry RmsEntry to write
* @return address of the written RmsEntry
* @throws RecordStoreException
*/
public Address logEntry(IRmsEntry entry) throws RecordStoreException {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(64);
DataOutputStream output = new DataOutputStream(bytesOut);
try {
output.writeByte(entry.getType());
entry.writeTo(output);
int padding = 0;
if ((bytesOut.size() & 1) == 1) {
bytesOut.write(0);
padding = 1;
}
output.close();
entry.setAddress(memoryHeap.allocateAndWriteBlock(bytesOut.toByteArray(), 0, bytesOut.size() - padding, memoryHeapScanner));
return entry.getAddress();
} catch (IOException e) {
throw new RecordStoreException(e.getMessage());
}
}
示例4: testAddRecordDeleteRecord1
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
@Test
public void testAddRecordDeleteRecord1() throws RecordStoreException {
assertNull(RecordStore.listRecordStores());
String storeName = "testAddRecordDeleteRecord1";
RecordStore store = RecordStore.openRecordStore(storeName, true);
byte[] record = new byte[1024];
int count = 0;
long startingSequence = ImpGlobal.getRecordStoreManagerErasedSequenceCurrentValue();
while ((ImpGlobal.getRecordStoreManagerErasedSequenceCurrentValue() - startingSequence) < erasedSequenceCount) {
fill(record, count);
int recordId = store.addRecord(record, 0, record.length);
fill(record, (byte) (count+1));
byte[] bytes = store.getRecord(recordId);
assertEquals(record, record.length, (byte) (count + 1));
assertEquals(bytes, bytes.length, (byte) count);
store.deleteRecord(recordId);
try {
store.getRecord(recordId);
fail();
} catch (InvalidRecordIDException e) {
}
count++;
}
store.closeRecordStore();
RecordStore.deleteRecordStore(storeName);
}
示例5: testSetRecord1
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
@Test
public void testSetRecord1() throws RecordStoreException {
assertNull(RecordStore.listRecordStores());
String storeName = "testSetRecord1";
RecordStore store = RecordStore.openRecordStore(storeName, true);
byte[] record = new byte[1024];
int count = 0;
int recordId = store.addRecord(record, 0, record.length);
long startingSequence = ImpGlobal.getRecordStoreManagerErasedSequenceCurrentValue();
while ((ImpGlobal.getRecordStoreManagerErasedSequenceCurrentValue() - startingSequence) < erasedSequenceCount) {
fill(record, count);
store.setRecord(recordId, record, 0, record.length);
byte[] bytes = store.getRecord(recordId);
assertEquals(bytes, bytes.length, count);
count++;
}
assertTrue(count > 0);
store.closeRecordStore();
RecordStore.deleteRecordStore(storeName);
}
示例6: testAllocateAndWriteBlock2
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testAllocateAndWriteBlock2() throws RecordStoreException {
final byte[] block = new byte[10];
for (int i=0; i < block.length; i++) {
block[i] = (byte) i;
}
final Address address = Address.fromPrimitive(9);
final NorFlashSectorState sector = new NorFlashSectorState(new SimulatedNorFlashSector(address, 1024, 0, false));
castHeap.currentSectorState = sector;
castHeap.hasScannedBlocks = true;
Address mallocAddress = heap.allocateAndWriteBlock(block, 0, block.length, null);
byte[] bytes = new byte[sector.getWriteHeadPosition()];
sector.flashSector.getBytes(0, bytes, 0, bytes.length);
assertEquals(0, bytes[0]);
assertEquals(0, bytes[1]);
assertEquals(0, bytes[2]);
assertEquals(block.length, bytes[3]);
assertEquals((byte) 0xFF, bytes[4]);
assertEquals((byte) 0xFF, bytes[5]);
for (int i=0; i < block.length; i++) {
assertEquals((byte) i, bytes[6+i]);
}
assertSame(address, mallocAddress);
}
示例7: testErase
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testErase() throws IOException, RecordStoreException {
byte[] erasedMarker = NorFlashSectorState.ERASED_HEADER;
final long sequence = 10;
sector.incrementFreedBlockCount();
sector.incrementAllocatedBlockCount();
sector.erase(sequence);
assertTrue(sector.hasErasedHeader());
assertEquals(NorFlashSectorState.ERASED_HEADER_SIZE, sector.getWriteHeadPosition());
assertEquals(0, sector.getFreedBlockCount());
assertEquals(0, sector.getAllocatedBlockCount());
byte[] bytes = new byte[testSize];
sector.readBytes(0, bytes, 0, testSize);
DataInputStream input = new DataInputStream(new ByteArrayInputStream(bytes));
assertEquals(NorFlashMemoryHeap.ERASED_VALUE_XOR, input.readByte());
assertEquals(NorFlashMemoryHeap.ERASED_VALUE_XOR, input.readByte());
for (int i=0; i < erasedMarker.length; i++) {
assertEquals(erasedMarker[i], input.readByte());
}
assertEquals(input.readLong(), sequence);
assertEquals(NorFlashMemoryHeap.ERASED_VALUE_XOR, input.readByte());
assertEquals(NorFlashMemoryHeap.ERASED_VALUE_XOR, input.readByte());
}
示例8: visitRecordEntry
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void visitRecordEntry(IRecordEntry record) throws RecordStoreException {
int recordId = record.getId();
int index = findRecordIndex(recordId);
if (index < 0) {
// record id was not found
index = -index - 1;
insertAtIndex(index);
recordIds[index] = recordId;
recordAddresses[index] = record.getAddress();
} else {
// record id was found, which means we had a failure to finish a prior setRecord operation
manager.invalidateEntryAt(recordAddresses[index]);
recordAddresses[index] = record.getAddress();
}
if (recordId > lastRecordId) {
lastRecordId = recordId;
}
}
示例9: testMakeRoomToWrite5
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testMakeRoomToWrite5() throws RecordStoreException {
final INorFlashSectorState sector1 = mock(INorFlashSectorState.class, "sector1");
final INorFlashSectorState sector2 = mock(INorFlashSectorState.class, "sector2");
castHeap.sectorStates = new INorFlashSectorState[] {sector1, sector2};
castHeap.currentSectorState = sector1;
castHeap.toBeErasedSectorStateList = mock(INorFlashSectorStateList.class);
expects(new InAnyOrder() {{
one(sector1).hasAvailable(0);will(returnValue(false));
one(sector1).getAllocatedBlockCount();will(returnValue(0));
one(castHeap.toBeErasedSectorStateList).addLast(sector1);
one(castHeap.toBeErasedSectorStateList).size();will(returnValue(2));
one(castHeap.toBeErasedSectorStateList).consumeFirst();will(returnValue(sector2));
one(sector2).erase(1L);
one(sector2).hasAvailable(0);will(returnValue(false));
one(sector2).getSize();will(returnValue(0));
}});
try {
castHeap.makeRoomToWrite(0, null);
fail();
} catch (RecordStoreFullException e) {
}
assertSame(sector2, castHeap.currentSectorState);
}
示例10: testGetSizeAvailable1
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testGetSizeAvailable1() throws RecordStoreException {
heap = castHeap;
castHeap.hasScannedBlocks = true;
castHeap.toBeErasedSectorStateList = mock(INorFlashSectorStateList.class);
expects(new InThisOrder() {{
INorFlashSectorState sector1 = mock(INorFlashSectorState.class);
INorFlashSectorState sector2 = mock(INorFlashSectorState.class);
castHeap.sectorStates = new INorFlashSectorState[] {sector1, sector2};
one(sector1).getSequence();will(returnValue(1L));
one(sector2).getSequence();will(returnValue(2L));
one(sector1).hasErasedHeader();will(returnValue(false));
one(castHeap.toBeErasedSectorStateList).addLast(sector1);
one(sector2).hasErasedHeader();will(returnValue(false));
one(castHeap.toBeErasedSectorStateList).addLast(sector2);
one(sector1).getSize();will(returnValue(2));
one(sector2).getSize();will(returnValue(10));
}});
int size = heap.getSizeAvailable();
assertEquals(2 + 10, size);
}
示例11: testMakeRoomToWrite4
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testMakeRoomToWrite4() throws RecordStoreException {
final INorFlashSectorState sector1 = mock(INorFlashSectorState.class, "sector1");
final INorFlashSectorState sector2 = mock(INorFlashSectorState.class, "sector2");
castHeap.sectorStates = new INorFlashSectorState[] {sector1, sector2};
castHeap.currentSectorState = sector1;
castHeap.toBeErasedSectorStateList = mock(INorFlashSectorStateList.class);
expects(new InAnyOrder() {{
one(sector1).hasAvailable(0);will(returnValue(false));
one(sector1).getAllocatedBlockCount();will(returnValue(0));
one(castHeap.toBeErasedSectorStateList).addLast(sector1);
one(castHeap.toBeErasedSectorStateList).size();will(returnValue(2));
one(castHeap.toBeErasedSectorStateList).consumeFirst();will(returnValue(sector2));
one(sector2).erase(1L);
one(sector2).hasAvailable(with(an(Integer.class)));will(returnValue(true));
}});
castHeap.makeRoomToWrite(0, null);
assertSame(sector2, castHeap.currentSectorState);
}
示例12: testSetRecord1
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testSetRecord1() throws RecordStoreException, IOException {
final int recordId = 1;
castStore.numRecords = 1;
castStore.recordIds[0] = recordId;
final Address originalAddress = Address.fromPrimitive(10);
final Address newAddress = Address.fromPrimitive(20);
castStore.recordAddresses[0] = originalAddress;
expects(new InThisOrder() {{
one(manager).logEntry(with(an(IRecordEntry.class)));will(returnValue(newAddress));
one(manager).invalidateEntryAt(originalAddress);
}});
store.setRecord(recordId, null, 0, 0);
assertEquals(1, castStore.numRecords);
assertEquals(1, castStore.recordIds[0]);
assertEquals(newAddress, castStore.recordAddresses[0]);
}
示例13: gcSector
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
/**
* Copy active blocks from src sector the currentSectorState. Src sector is then "to be erased".
* @param src sector to be GCed.
* @param scanner scanner is responsible for copying a record from src to currentSectorState.
* @throws RecordStoreException
*/
protected void gcSector(INorFlashSectorState src, INorFlashMemoryHeapScanner scanner) throws RecordStoreException {
inUseSectorStateList.remove(src);
src.resetHead();
int offset = src.getWriteHeadPosition();
Address startAddress = src.getStartAddress();
MemoryHeapBlock block = new MemoryHeapBlock();
while (true) {
if (!getBlockAt(block, src, offset)) {
break;
}
if (block.isAllocated) {
writeBlock(block, scanner, startAddress.add(offset));
}
offset = block.getNextBlockOffset();
}
src.removeErasedHeader(); // mark sector "stale"
toBeErasedSectorStateList.addLast(src);
}
示例14: testVisitRecordEntryExists
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testVisitRecordEntryExists() throws RecordStoreException, IOException {
final IRecordEntry record = mock(IRecordEntry.class);
final int recordId = 1;
final Address existingAddress = Address.fromPrimitive(10);
final Address newAddress = Address.fromPrimitive(11);
castStore.recordIds[0] = recordId;
castStore.recordAddresses[0] = existingAddress;
castStore.numRecords = 1;
expects(new InThisOrder() {{
one(record).getId();will(returnValue(recordId));
one(manager).invalidateEntryAt(existingAddress);
one(record).getAddress();will(returnValue(newAddress));
}});
store.visitRecordEntry(record);
assertSame(1, store.getNumRecords());
assertSame(recordId, castStore.recordIds[0]);
assertSame(newAddress, castStore.recordAddresses[0]);
}
示例15: testCheckMIDletVersion
import javax.microedition.rms.RecordStoreException; //导入依赖的package包/类
public void testCheckMIDletVersion() throws RecordStoreException {
final String midletName = "name";
final String midletVendor = "vendor";
final String midletVersion = "version";
assertNotNull(castManager.checkMIDletVersion(midletName, midletVendor, midletVersion));
final IApplicationDescriptorEntry applicationEntry = mock(IApplicationDescriptorEntry.class);
castManager.currentApplicationDescriptor = applicationEntry;
expects(new InAnyOrder() {{
allowing(applicationEntry).getMidletName();will(returnValue(midletName));
allowing(applicationEntry).getMidletVendor();will(returnValue(midletVendor));
allowing(applicationEntry).getMidletVersion();will(returnValue(midletVersion));
}});
assertNull(castManager.checkMIDletVersion(midletName, midletVendor, midletVersion));
assertNotNull(castManager.checkMIDletVersion(null, null, null));
assertNotNull(castManager.checkMIDletVersion(midletName, null, null));
assertNotNull(castManager.checkMIDletVersion(midletName, midletVendor, null));
assertNotNull(castManager.checkMIDletVersion(null, midletVendor, midletVersion));
assertNotNull(castManager.checkMIDletVersion(midletName, null, midletVersion));
assertNotNull(castManager.checkMIDletVersion(midletName, midletVendor, null));
assertNotNull(castManager.checkMIDletVersion(null, null, midletVersion));
}