Search in sources :

Example 1 with BinaryData

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());
}
Also used : BinaryData(org.exbin.utils.binary_data.BinaryData) Test(org.junit.Test)

Example 2 with BinaryData

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);
    }
}
Also used : CodeAreaUtils(org.exbin.deltahex.CodeAreaUtils) SelectionRange(org.exbin.deltahex.SelectionRange) BinaryData(org.exbin.utils.binary_data.BinaryData) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Example 3 with 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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with BinaryData

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with BinaryData

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

BinaryData (org.exbin.utils.binary_data.BinaryData)18 EditableBinaryData (org.exbin.utils.binary_data.EditableBinaryData)14 IOException (java.io.IOException)8 Test (org.junit.Test)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 SelectionRange (org.exbin.deltahex.SelectionRange)5 SelectionCapable (org.exbin.deltahex.capability.SelectionCapable)5 CodeAreaUtils (org.exbin.deltahex.CodeAreaUtils)4 CodeType (org.exbin.deltahex.CodeType)4 CaretPosition (org.exbin.deltahex.CaretPosition)2 CodeCharactersCase (org.exbin.deltahex.CodeCharactersCase)2 CodeCharactersCaseCapable (org.exbin.deltahex.capability.CodeCharactersCaseCapable)2 CodeTypeCapable (org.exbin.deltahex.capability.CodeTypeCapable)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Stroke (java.awt.Stroke)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 CaretCapable (org.exbin.deltahex.capability.CaretCapable)1