allow multiple loading of same format
This commit is contained in:
parent
1ebf9ba382
commit
ff87e72510
|
@ -2,12 +2,12 @@
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
|
<classpathentry kind="src" path="src/"/>
|
||||||
<classpathentry exported="true" kind="lib" path="lib/mapdb-3.0.7.jar" sourcepath="lib/mapdb-3.0.7-sources.jar">
|
<classpathentry exported="true" kind="lib" path="lib/mapdb-3.0.7.jar" sourcepath="lib/mapdb-3.0.7-sources.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="javadoc_location" value="jar:platform:/resource/com.minres.scviewer.database.text/lib/mapdb-3.0.7-javadoc.jar!/"/>
|
<attribute name="javadoc_location" value="jar:platform:/resource/com.minres.scviewer.database.text/lib/mapdb-3.0.7-javadoc.jar!/"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry exported="true" kind="lib" path="lib/kotlin-stdlib-1.2.42.jar"/>
|
<classpathentry exported="true" kind="lib" path="lib/kotlin-stdlib-1.2.42.jar"/>
|
||||||
<classpathentry exported="true" kind="lib" path="lib/lz4-1.3.0.jar"/>
|
<classpathentry exported="true" kind="lib" path="lib/lz4-1.3.0.jar"/>
|
||||||
<classpathentry exported="true" kind="lib" path="lib/elsa-3.0.0-M5.jar"/>
|
<classpathentry exported="true" kind="lib" path="lib/elsa-3.0.0-M5.jar"/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="TextDbLoader">
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="TextDbLoaderFactory">
|
||||||
<implementation class="com.minres.scviewer.database.text.TextDbLoader"/>
|
<implementation class="com.minres.scviewer.database.text.TextDbLoaderFactory"/>
|
||||||
<service>
|
<service>
|
||||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
<provide interface="com.minres.scviewer.database.IWaveformDbLoaderFactory"/>
|
||||||
</service>
|
</service>
|
||||||
</scr:component>
|
</scr:component>
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 IT Just working.
|
||||||
|
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IT Just working - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package com.minres.scviewer.database.text;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||||
|
import com.minres.scviewer.database.IWaveformDbLoaderFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class TextDbLoader.
|
||||||
|
*/
|
||||||
|
public class TextDbLoaderFactory implements IWaveformDbLoaderFactory {
|
||||||
|
|
||||||
|
/** The Constant x. */
|
||||||
|
static final byte[] x = "scv_tr_stream".getBytes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if f is gzipped.
|
||||||
|
*
|
||||||
|
* @param f the f
|
||||||
|
* @return true, if is gzipped
|
||||||
|
*/
|
||||||
|
private static boolean isGzipped(File f) {
|
||||||
|
try (InputStream is = new FileInputStream(f)) {
|
||||||
|
byte[] signature = new byte[2];
|
||||||
|
int nread = is.read(signature); // read the gzip signature
|
||||||
|
return nread == 2 && signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can load.
|
||||||
|
*
|
||||||
|
* @param inputFile the input file
|
||||||
|
* @return true, if successful
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean canLoad(File inputFile) {
|
||||||
|
if (!inputFile.isDirectory() && inputFile.exists()) {
|
||||||
|
boolean gzipped = isGzipped(inputFile);
|
||||||
|
try(InputStream stream = gzipped ? new GZIPInputStream(new FileInputStream(inputFile)) : new FileInputStream(inputFile)){
|
||||||
|
byte[] buffer = new byte[x.length];
|
||||||
|
int readCnt = stream.read(buffer, 0, x.length);
|
||||||
|
if (readCnt == x.length) {
|
||||||
|
for (int i = 0; i < x.length; i++)
|
||||||
|
if (buffer[i] != x[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWaveformDbLoader getLoader() {
|
||||||
|
return new TextDbLoader();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="VCDDbLoader">
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="VCDDbLoaderFactory">
|
||||||
<implementation class="com.minres.scviewer.database.vcd.VCDDbLoader"/>
|
<implementation class="com.minres.scviewer.database.vcd.VCDDbLoaderFactory"/>
|
||||||
<service>
|
<service>
|
||||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
<provide interface="com.minres.scviewer.database.IWaveformDbLoaderFactory"/>
|
||||||
</service>
|
</service>
|
||||||
</scr:component>
|
</scr:component>
|
||||||
|
|
|
@ -164,7 +164,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||||
@Override
|
@Override
|
||||||
public void enterModule(String tokenString) {
|
public void enterModule(String tokenString) {
|
||||||
if(moduleStack.isEmpty()) {
|
if(moduleStack.isEmpty()) {
|
||||||
if("SystemC".compareTo(tokenString)!=0) moduleStack.push(tokenString);
|
if("SystemC".compareTo(tokenString)!=0)
|
||||||
|
moduleStack.push(tokenString);
|
||||||
} else
|
} else
|
||||||
moduleStack.push(moduleStack.peek()+"."+tokenString);
|
moduleStack.push(moduleStack.peek()+"."+tokenString);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* MINRES Technologies GmbH - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package com.minres.scviewer.database.vcd;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||||
|
import com.minres.scviewer.database.IWaveformDbLoaderFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class VCDDb.
|
||||||
|
*/
|
||||||
|
public class VCDDbLoaderFactory implements IWaveformDbLoaderFactory {
|
||||||
|
/**
|
||||||
|
* Checks if is gzipped.
|
||||||
|
*
|
||||||
|
* @param f the f
|
||||||
|
* @return true, if is gzipped
|
||||||
|
*/
|
||||||
|
private static boolean isGzipped(File f) {
|
||||||
|
try (InputStream is = new FileInputStream(f)) {
|
||||||
|
byte [] signature = new byte[2];
|
||||||
|
int nread = is.read( signature ); //read the gzip signature
|
||||||
|
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can load.
|
||||||
|
*
|
||||||
|
* @param inputFile the input file
|
||||||
|
* @return true, if successful
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean canLoad(File inputFile) {
|
||||||
|
if(!inputFile.isDirectory() || inputFile.exists()) {
|
||||||
|
String name = inputFile.getName();
|
||||||
|
if(!(name.endsWith(".vcd") ||
|
||||||
|
name.endsWith(".vcdz") ||
|
||||||
|
name.endsWith(".vcdgz") ||
|
||||||
|
name.endsWith(".vcd.gz")) )
|
||||||
|
return false;
|
||||||
|
boolean gzipped = isGzipped(inputFile);
|
||||||
|
try(InputStream stream = gzipped ? new GZIPInputStream(new FileInputStream(inputFile)) : new FileInputStream(inputFile)){
|
||||||
|
byte[] buffer = new byte[8];
|
||||||
|
if (stream.read(buffer, 0, buffer.length) == buffer.length) {
|
||||||
|
return buffer[0]=='$';
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWaveformDbLoader getLoader() {
|
||||||
|
return new VCDDbLoader();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database.loader">
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database.loader">
|
||||||
<implementation class="com.minres.scviewer.database.internal.WaveformDb"/>
|
<implementation class="com.minres.scviewer.database.internal.WaveformDb"/>
|
||||||
<reference bind="bind" cardinality="1..n" interface="com.minres.scviewer.database.IWaveformDbLoader" name="IWaveformDbLoader" policy="dynamic" unbind="unbind"/>
|
<reference bind="bind" cardinality="1..n" interface="com.minres.scviewer.database.IWaveformDbLoaderFactory" name="IWaveformDbLoaderFactory" policy="dynamic" unbind="unbind"/>
|
||||||
</scr:component>
|
</scr:component>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* MINRES Technologies GmbH - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package com.minres.scviewer.database;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory for creating IWaveformDb objects.
|
||||||
|
*/
|
||||||
|
public interface IWaveformDbLoaderFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the loader produced by this factory can load the given file.
|
||||||
|
*
|
||||||
|
* @param inputFile the input file
|
||||||
|
* @return true, if successful
|
||||||
|
*/
|
||||||
|
public boolean canLoad(File inputFile);
|
||||||
|
/**
|
||||||
|
* Gets the database.
|
||||||
|
*
|
||||||
|
* @return the database
|
||||||
|
*/
|
||||||
|
IWaveformDbLoader getLoader();
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ import com.minres.scviewer.database.IHierNode;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
import com.minres.scviewer.database.IWaveformDb;
|
import com.minres.scviewer.database.IWaveformDb;
|
||||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||||
|
import com.minres.scviewer.database.IWaveformDbLoaderFactory;
|
||||||
import com.minres.scviewer.database.RelationType;
|
import com.minres.scviewer.database.RelationType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +34,7 @@ import com.minres.scviewer.database.RelationType;
|
||||||
public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeListener {
|
public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeListener {
|
||||||
|
|
||||||
/** The loaders. */
|
/** The loaders. */
|
||||||
private static List<IWaveformDbLoader> loaders = new LinkedList<>();
|
private static List<IWaveformDbLoaderFactory> loaderFactories = new LinkedList<>();
|
||||||
|
|
||||||
/** The loaded. */
|
/** The loaded. */
|
||||||
private boolean loaded;
|
private boolean loaded;
|
||||||
|
@ -52,8 +53,8 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
||||||
*
|
*
|
||||||
* @param loader the loader
|
* @param loader the loader
|
||||||
*/
|
*/
|
||||||
public synchronized void bind(IWaveformDbLoader loader) {
|
public synchronized void bind(IWaveformDbLoaderFactory loader) {
|
||||||
loaders.add(loader);
|
loaderFactories.add(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,8 +62,8 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
||||||
*
|
*
|
||||||
* @param loader the loader
|
* @param loader the loader
|
||||||
*/
|
*/
|
||||||
public synchronized void unbind(IWaveformDbLoader loader) {
|
public synchronized void unbind(IWaveformDbLoaderFactory loader) {
|
||||||
loaders.remove(loader);
|
loaderFactories.remove(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +71,8 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
||||||
*
|
*
|
||||||
* @return the loaders
|
* @return the loaders
|
||||||
*/
|
*/
|
||||||
public static List<IWaveformDbLoader> getLoaders() {
|
public static List<IWaveformDbLoaderFactory> getLoaders() {
|
||||||
return Collections.unmodifiableList(loaders);
|
return Collections.unmodifiableList(loaderFactories);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,8 +125,9 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
||||||
@Override
|
@Override
|
||||||
public boolean load(File inp) {
|
public boolean load(File inp) {
|
||||||
boolean retval = true;
|
boolean retval = true;
|
||||||
for (IWaveformDbLoader loader : loaders) {
|
for (IWaveformDbLoaderFactory loaderFactory : loaderFactories) {
|
||||||
if (loader.canLoad(inp)) {
|
if (loaderFactory.canLoad(inp)) {
|
||||||
|
IWaveformDbLoader loader = loaderFactory.getLoader();
|
||||||
loader.addPropertyChangeListener(this);
|
loader.addPropertyChangeListener(this);
|
||||||
try {
|
try {
|
||||||
loader.load(this, inp);
|
loader.load(this, inp);
|
||||||
|
|
Loading…
Reference in New Issue