use of org.exbin.utils.binary_data.BinaryData in project deltahex-java by exbin.
the class DeltaDocumentTest method testInsertBinaryData.
@Test
public void testInsertBinaryData() {
DeltaDocument document = openDeltaDocument();
BinaryData data = new MemoryDataSource(new byte[] { 0 });
document.insert(10, data);
assertEquals(SAMPLE_ALLBYTES_SIZE + 1, document.getDataSize());
DefaultDoublyLinkedList<DataSegment> segments = document.getSegments();
assertEquals(3, segments.size());
DataSegment segment0 = segments.first();
assertTrue(segment0 instanceof FileSegment);
assertEquals(0, ((FileSegment) segment0).getStartPosition());
assertEquals(10, segment0.getLength());
DataSegment segment1 = segments.get(1);
assertTrue(segment1 instanceof MemorySegment);
assertEquals(0, ((MemorySegment) segment1).getStartPosition());
assertEquals(1, segment1.getLength());
DataSegment segment2 = segments.get(2);
assertTrue(segment2 instanceof FileSegment);
assertEquals(10, ((FileSegment) segment2).getStartPosition());
assertEquals(SAMPLE_ALLBYTES_SIZE - 10, segment2.getLength());
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
}
use of org.exbin.utils.binary_data.BinaryData in project deltahex-java by exbin.
the class CodeAreaOperationCommandHandler method copy.
@Override
public void copy() {
SelectionRange selection = ((SelectionCapable) codeArea.getWorker()).getSelection();
if (!selection.isEmpty()) {
long first = selection.getFirst();
long last = selection.getLast();
BinaryData copy = codeArea.getData().copy(first, last - first + 1);
CodeAreaUtils.BinaryDataClipboardData binaryData = new CodeAreaUtils.BinaryDataClipboardData(copy, binaryDataFlavor);
setClipboardContent(binaryData);
}
}
use of org.exbin.utils.binary_data.BinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testInsertCopyBeginSaveDocument.
@Test
public void testInsertCopyBeginSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
BinaryData copy = document.copy(0x40, 2);
document.insert(0, copy);
document.validatePointerPosition();
copy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_INSERTED_BEGIN).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
use of org.exbin.utils.binary_data.BinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testInsertCopyEndSaveDocument.
@Test
public void testInsertCopyEndSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
BinaryData copy = document.copy(0x40, 2);
document.insert(256, copy);
document.validatePointerPosition();
copy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_INSERTED_END).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
use of org.exbin.utils.binary_data.BinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testOverwriteCopyMiddleSaveDocument.
@Test
public void testOverwriteCopyMiddleSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
BinaryData copy = document.copy(0x40, 2);
document.replace(120, copy);
document.validatePointerPosition();
copy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_OVERWRITTEN_MIDDLE).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
Aggregations