@normen said:
You'd have to create an inputStream like JmeSystem does.
Hi normen,
Please, check the following changes:
- Added ProjectAssetManager.getResourceAsStream(String name) method. It gets a j3md file.
- Changes Set intead of Arraylist for j3md file names in order to avoid duplicates.
[patch]
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -7,7 +7,6 @@
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.material.MatParam;
import com.jme3.material.Material;
-import com.jme3.system.JmeSystem;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -177,7 +176,7 @@
fs = FileUtil.createMemoryFileSystem();
matDef = fs.getRoot().createData(name, "j3md");
OutputStream out = matDef.getOutputStream();
- InputStream in = JmeSystem.getResourceAsStream("/" + getMatDefName());
+ InputStream in = manager.getResourceAsStream(getMatDefName());
if (in != null) {
int input = in.read();
while (input != -1) {
[/patch]
[patch]
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -35,14 +35,18 @@
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.java.classpath.ClassPath;
@@ -329,7 +333,8 @@
* @return
*/
private String[] collectFilesWithSuffix(String suffix) {
- ArrayList<String> list = new ArrayList<String>();
+// ArrayList<String> list = new ArrayList<String>();
+ Set<String> list = new HashSet<String>();
FileObject assetsFolder = getAssetFolder();
if (assetsFolder != null) {
Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);
@@ -495,4 +500,32 @@
public void classPathChanged(ProjectAssetManager manager);
}
+
+ public InputStream getResourceAsStream(String name) {
+ InputStream in = this.getClass().getResourceAsStream(name);
+
+ if (in == null && classPathItems != null) {
+ // TODO I need to find out if classPathItems contains all jars added to a project
+ Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
+ while (classPathItemsIter.hasNext()) {
+ ClassPathItem classPathItem = classPathItemsIter.next();
+ FileObject jarFile = classPathItem.object;
+
+ Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
+ while (jarEntry.hasMoreElements()) {
+ FileObject jarEntryAsset = jarEntry.nextElement();
+ if (jarEntryAsset.getPath().equalsIgnoreCase(name)) {
+ try {
+ in = jarEntryAsset.getInputStream();
+ } catch (FileNotFoundException ex) {
+ Exceptions.printStackTrace(ex);
}
+ break;
+ }
+ }
+ }
+ }
+
+ return in;
+ }
+}
[/patch]