package com.ximple.io.dgn7;
|
|
import org.apache.commons.io.FileUtils;
|
import org.apache.log4j.Logger;
|
import org.geotools.TestData;
|
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.Test;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.io.RandomAccessFile;
|
import java.nio.channels.FileChannel;
|
|
public class Dgn7fileWriterTest {
|
private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class);
|
|
// private final static String testFilePath = "test-data\\testHV.dgn";
|
private final static String testFilePath = "testHV.dgn";
|
private FileInputStream _fs;
|
|
@BeforeTest
|
public void setUp() throws IOException {
|
File dataFile = TestData.file(this, testFilePath);
|
if (!dataFile.exists()) {
|
return;
|
}
|
|
_fs = new FileInputStream(dataFile);
|
}
|
|
@Test
|
public void testWrite() {
|
}
|
|
@Test
|
public void testCopy() throws Dgn7fileException, IOException {
|
File target = TestData.temp(this, "testdgn2d.dgn");
|
FileUtils.copyFile(TestData.file(this, "dgnseed2d.dgn"), target);
|
RandomAccessFile targetStream = new RandomAccessFile(target, "rw");
|
FileChannel fctarget = targetStream.getChannel();
|
Lock lock = new Lock();
|
|
Dgn7fileReader targetReader = new Dgn7fileReader(fctarget, new Lock());
|
while (targetReader.hasNext()) {
|
targetReader.nextElement();
|
}
|
|
Dgn7fileWriter writer = new Dgn7fileWriter(fctarget, lock);
|
|
FileChannel fc = _fs.getChannel();
|
Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock());
|
int count = 0;
|
Element lastComplex = null;
|
while (reader.hasNext()) {
|
Element.FileRecord record = reader.nextElement();
|
if (record.element() != null) {
|
Element element = (Element) record.element();
|
ElementType type = element.getElementType();
|
|
if ((!type.isComplexElement()) && (!element.isComponentElement())) {
|
if (lastComplex != null) {
|
// @todo add process in here
|
lastComplex = null;
|
}
|
|
// @todo add process in here
|
} else if (element.isComponentElement()) {
|
if (lastComplex != null) {
|
((ComplexElement) lastComplex).add(element);
|
}
|
} else if (type.isComplexElement()) {
|
if (lastComplex == null) {
|
lastComplex = element;
|
} else {
|
// @todo add process in here
|
lastComplex = element;
|
}
|
}
|
|
if (element.getElementType().isComplexElement()) {
|
if (element instanceof ComplexChainElement) {
|
ComplexChainElement complexChain = (ComplexChainElement) element;
|
int size = complexChain.size();
|
for (Object aComplexChain : complexChain) {
|
Element subElement = (Element) aComplexChain;
|
subElement.getType();
|
}
|
}
|
|
if (element instanceof ComplexShapeElement) {
|
ComplexShapeElement complexShape = (ComplexShapeElement) element;
|
}
|
|
if (element instanceof TextNodeElement) {
|
TextNodeElement textNode = (TextNodeElement) element;
|
int size = textNode.size();
|
for (int i = 0; i < size; i++) {
|
Element subElement = textNode.get(i);
|
subElement.getElementType();
|
}
|
}
|
}
|
|
writer.writeElement(element);
|
}
|
count++;
|
}
|
writer.writeEOF();
|
writer.close();
|
|
// FileUtils.copyFile(target, new File("G://target.dgn"));
|
}
|
}
|