IOException Loading Data into BlazegraphEmbedded - java

I'm having an issue loading my Blazegraph properties file into an embedded instance. When I try to import my .properties file into my Java class, I get the following error:
Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.Reader.read(Unknown Source)
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at blazegraph_tinkerpop_tryout.blazegraph_data_load.loadProperties(blazegraph_data_load.java:55)
at blazegraph_tinkerpop_tryout.blazegraph_data_load.main(blazegraph_data_load.java:32)
Call to loadProperties function from main:
Properties props = loadProperties("sampleprops.properties");
My loadProperties function (checking to see whether file path is valid, then sending to reader):
public static Properties loadProperties(String resource) throws IOException
{
Properties p = new Properties();
Path path = Paths.get(resource);
Boolean bool = Files.exists(path);
if (bool)
{
System.out.println("File was found. Attempting data load...");
InputStream is = blazegraph_data_load.class.getResourceAsStream(resource);
p.load(new InputStreamReader(new BufferedInputStream(is)));
return p;
}
System.out.println("The file you entered was not found.");
return null;
}
Here is what my file sampleprops.properties looks like:
com.bigdata.journal.AbstractJournal.bufferMode=DiskRW
com.bigdata.journal.AbstractJournal.file=blazegraph.jnl
I have been following the setup instructions from the sample Blazegraph app described here. If it makes a difference, I am using the Blazegraph/Tinkerpop3 implementation found here.

I found a workaround: I switched my getResourceAsStream method to a FileInputStream method.
The problem was with the placement of my properties file. The FileInputStream method seems more forgiving in where you place the file.

Related

java.io.IOException: Stream closed when unmarshaling with JAXBContext

I wrote an unmarshal method which is accessed by a bunch of tests running in parallel to read data from XML files.
This method sits in a maven commons dependency module added to my main module.
I am facing java.io.IOException: Stream closed exception in a very inconsistent fashion and cannot reproduce it locally. It only happens when my tests run in CI in Jenkins and that too not very often. Code is below.
public <T> Object internalUnmarshal(String url, Class<T> clazz)
throws JAXBException,DataException, ClassNotFoundException,IOException
{
InputStream is = getClass().getResourceAsStream(url);
try {
if (is == null) {
throw new DataException("''{0}'' not found.", url);
}
JAXBContext jaxbContext = JAXBContext
.newInstance(Class.forName(clazz.getCanonicalName());
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return unmarshaller.unmarshal(is);
} catch (JAXBException e) {
throw new JAXBException(e);
} finally {
is.close();
}
}
I even added a synchronized block as below but same issue was reproduced in jenkins server run.
synchronized(this){
return unmarshaller.unmarshal(is);
}
Stack trace below :-
[javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.IOException: Stream closed]]
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.internalUnmarshal(XMLUnmarshaler.java:116)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.resloveToUnmarshaledObjectList(XMLUnmarshaler.java:76)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.doUnmarshalObjects(XMLUnmarshaler.java:36)
... 67 more
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.IOException: Stream closed]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:261)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:229)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:204)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.internalUnmarshal(XMLUnmarshaler.java:112)
... 69 more
Caused by: java.io.IOException: Stream closed
at java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:121)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:258)
... 73 more
Any ideas what might be causing this ?

in java catch can't catch exception with jsoup

I want to parse a website with jsoup, and it succeeded to get the detail what I want, but I still get many many exceptions and not in catch
public static void main(String[] argv)
{
getGoogle();
}
private static void getGoogle() {
String url = "http://google.com";
Document doc = null;
try {
doc = Jsoup.connect(url).get();
Element body = doc.body();
}catch (Exception e) {
System.out.println("------------google------------");
System.out.println("getGoogle:" + e.getMessage());
}
}
when I use debug mode found it was because doc = Jsoup.connect(url).get(); this line, but it looks ok after I search much info, below is exceptions I got
Could not instrument class com/sun/deploy/security/MozillaJSSProvider: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1099)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:562)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:608)
at java.base/java.lang.Class.forName(Class.java:448)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:847)
at java.base/java.util.ServiceLoader.access$600(ServiceLoader.java:390)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1071)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1294)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1379)
at java.base/sun.security.jca.ProviderConfig$ProviderLoader.load(ProviderConfig.java:334)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:244)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:238)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.security.jca.ProviderConfig.doLoadProvider(ProviderConfig.java:238)
at java.base/sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:218)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:266)
at java.base/sun.security.jca.ProviderList.getIndex(ProviderList.java:296)
at java.base/sun.security.jca.ProviderList.getProviderConfig(ProviderList.java:280)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:286)
at java.base/java.security.Security.getProvider(Security.java:470)
at java.base/sun.security.ssl.SignatureAndHashAlgorithm.<clinit>(SignatureAndHashAlgorithm.java:415)
at java.base/sun.security.ssl.SSLSessionImpl.<init>(SSLSessionImpl.java:182)
at java.base/sun.security.ssl.SSLSessionImpl.<init>(SSLSessionImpl.java:150)
at java.base/sun.security.ssl.SSLSessionImpl.<clinit>(SSLSessionImpl.java:79)
at java.base/sun.security.ssl.SSLSocketImpl.init(SSLSocketImpl.java:596)
at java.base/sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:534)
at java.base/sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:72)
at java.base/sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:413)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:162)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:651)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:676)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:676)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:628)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:260)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:249)
at test3.test3.getGoogle(test3.java:23)
at test3.test3.main(test3.java:12)
Could not instrument class com/sun/deploy/security/MozillaJSSProvider$ProviderService: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class com/sun/deploy/security/MozillaJSSProvider$ProviderService: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/SunPKCS11: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/wrapper/PKCS11Exception: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/SunPKCS11$Descriptor: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class com/sun/security/sasl/gsskerb/JdkSASL: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
Could not instrument class com/sun/security/sasl/gsskerb/JdkSASL$1: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
and more more exceptions.....and all not catch by try...catch
It is an eclipse bug, you can find the discussion here
Also, this has been raised in SO as well, this (https://stackoverflow.com/a/47109099/6039974) answer might help you.

Java Download massive file giving Connection Shutdown/Reset on internet url after sometime

I am building a swing application to download multiple files over the internet and save to a windows fileshare. I have used SwingWroker which internally uses the ExecutorService which internally queues them and downloads 10 at a time, but for some reason after downloading say 2 - 3 MB of file it stops and moves to next downloading file, They are downloaded in a batch of 10 as SwingWorker has fixed it in number of Threads for the Executor Service.
I have to write these files in a windows file share and I am using nio.FileChannels to do that. There are files ranging from 50-60 each weighing around 300MB - 500MB. The file links are located on a webpage to where I get to by login in using credentials on a login page(with a post request) over the internet before that I specify CookieHandler.setDefault(new CookieManager()) at the beginning and so it behaves like a browser to me.
Another observation is when I download them locally (not to a windows server share) they do work fine.
This is the code I am using
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import javax.swing.SwingWorker;
public class DownloadProcess extends SwingWorker<Boolean, String> {
private String urlPath, filePath;
public DownloadProcess(String urlPath, String filePath){
this.urlPath = urlPath;
this.filePath = filePath;
}
#Override
protected Boolean doInBackground() {
boolean taskState = true;
URLConnection httpConn = null;
ReadableByteChannel readableByteChannel = null;
FileOutputStream fileOutputStream = null;
FileChannel fileOutputChannel = null;
try{
//String filePath = "\\\\fileshare.server\\xyz.txt";
//String urlPath = "http://example.com/anyBigFile.1GB.docx";
File localFile = new File(filePath);//File share
boolean itsThere = localFile!=null && localFile.exists();
long done = itsThere ? localFile.length() : 0;
URL url = new URL(urlPath);
httpConn = url.openConnection();
httpConn.setRequestProperty("Connection", "keep-alive");
if(itsThere) {
httpConn.setRequestProperty("Range","bytes="+done+"-");
}
readableByteChannel = Channels.newChannel(httpConn.getInputStream());
fileOutputStream = itsThere ? new FileOutputStream(filePath) : new FileOutputStream(filePath,true);
fileOutputChannel = fileOutputStream.getChannel();
for (long position = done, size = httpConn.getContentLength(); position < size && !isCancelled(); ) {
position += fileOutputChannel.transferFrom(readableByteChannel, position, 1 << 16);
}
//done
}catch(Exception e){
taskState = false;
e.printStackTrace();
}finally{
//close streams conns etc
}
return taskState;
}
}
This is the error stack trace that I get after 5 - 10 mins of download
/*
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.MeteredStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at java.nio.channels.Channels$ReadableByteChannelImpl.read(Unknown Source)
at com.objects.DownloadByteChannel.read(DownloadByteChannel.java:117)
at sun.nio.ch.FileChannelImpl.transferFromArbitraryChannel(Unknown Source)
at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
at com.core.DownloadTask.doInBackground(DownloadTask.java:154)
at com.core.DownloadTask.doInBackground(DownloadTask.java:59)
at com.util.ZSwingWorker$1.call(ZSwingWorker.java:286)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.util.ZSwingWorker.run(ZSwingWorker.java:325)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
... 18 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
... 18 more
*/
Usage:
public static void main(String[] args){
int counter = 1;
for(String url: urls){
new DownloadProcess(url,"\\\\fileshare.server\\xyz"+(counter++)+".txt").execute();
}
}
You are going to have to change your connection timeout serverside. I picked up a few links along the way if they are of any importance:
Modify Session Security settings
Lengthening salesforce session timeout
Hope this helps, good luck and let me know :)
Connection Reset means the remote side is closing the connection with a TCP RST (reset) packet. You need to find out what the remote side isn't liking and fix it.
If the remote side is Apache maybe you are running into the KeepAliveTimeout value. By default that is 5 seconds. It really sounds like you are running into some sort of configured limit on the remote side. When that happens the server is kicking you off with a reset.

Java ClassLoader - Casting methods in external jars

Im trying to create a plugin system for one of my java project so I was trying to do it with classloader but when I try my method it gives me a ClassNotFound exception. I just can't get it working could someone help me with this? Sorry for my bad english.
my method:
public void loadPlugin(String jarname) throws Exception {
File f = new File("server'\\" + jarname + ".jar");
URL url = f.toURL();
URL[] urls = new URL[]{url};
URLClassLoader child = new URLClassLoader (urls, this.getClass().getClassLoader());
Class classToLoad = Class.forName ("me.daansander.plugin.Plugin", true, child);
Method method = classToLoad.getDeclaredMethod ("onEnable");
Object instance = classToLoad.newInstance ();
Object result = method.invoke (instance);
StackTrace:
java.lang.ClassNotFoundException: me.daansander.plugin.Plugin
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at me.daansander.serverchecker.plugin.ServerPlugin.loadPlugin(ServerPlug
in.java:59)
at me.daansander.serverchecker.plugin.ServerPlugin.start(ServerPlugin.ja
va:40)
at me.daansander.serverchecker.ServerChecker.<init>(ServerChecker.java:3
9)
at me.daansander.serverchecker.ServerChecker.main(ServerChecker.java:124
)
For Class.forName() to work you'd have to register your new classloader via Thread.currentThread().setContextClassLoader(myClassLoader).
See also https://stackoverflow.com/a/4096399/1015327.
Alternatively, you could try myClassloader.findClass().

JFileChooser remote view

I've been implementing a JFileChooser as a view for remote file system. When getFiles() is called from the FileSystemView I send request to the remote system with the directory location data.
Then asynchronously I receive back packet containing all files in the directory I am browsing, after that I am setting the files ready for updating view(so that next time getFiles() is called it will return the received array of files) but the problem is that I don't know how to update the JFileChoosers view.
I've tried
fileChooser.updateUI();
but it throws the following exception:
Exception in thread "pool-1-thread-31" java.lang.NullPointerException
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.setDirectorySelected(Unknown Source)
at javax.swing.plaf.basic.BasicFileChooserUI$Handler.valueChanged(Unknown Source)
at javax.swing.JList.fireSelectionValueChanged(Unknown Source)
at javax.swing.JList$ListSelectionHandler.valueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.moveLeadSelectionIndex(Unknown Source)
at sun.swing.FilePane.clearSelection(Unknown Source)
at sun.swing.FilePane.doFilterChanged(Unknown Source)
at sun.swing.FilePane.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.fire(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JFileChooser.setFileFilter(Unknown Source)
at javax.swing.JFileChooser.addChoosableFileFilter(Unknown Source)
at javax.swing.JFileChooser.updateUI(Unknown Source)
at com.ruuhkis.remoteserver.ui.RemoteView.updateFiles(RemoteView.java:252)
at com.ruuhkis.remoteserver.ui.RemoteApplication.onFileListReceived(RemoteApplication.java:122)
at com.ruuhkis.remoteserver.packets.impl.FileListPacket.handlePacket(FileListPacket.java:32)
at com.ruuhkis.remoteserver.packets.PacketHandler$1.run(PacketHandler.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
when I am on the directory and I know it has received new file list and I press f5 it will show the new files it just loaded, how can I make it so I don't have to press f5? Also by pressing f5 it causes the system to reload the pre existing data for the directory.
current code is basically:
view = new FileSystemView() {
int c;
#Override
public File[] getFiles(File dir, boolean useFileHiding) {
if(!auto) {
PacketBuilder builder = new PacketBuilder(OpCodes.FILE_LIST_REQUEST_PACKET.getOpCode());
root = dir.getAbsolutePath();
builder.writeString(dir.getAbsolutePath());
builder.write(RemoteView.this.remote.getChannel());
}
auto = false;
if(dirContent == null)
return new File[]{new File((c++) + ".txt")};
else
return dirContent;
}
#Override
public Boolean isTraversable(File arg0) {
return true;
}
#Override
public File createNewFolder(File arg0) throws IOException {
// TODO Auto-generated method stub
return null;
}
};
c was basically just for testing so I can see if the system gets refreshed
when I receive the file list I do this:
public void updateFiles(String list) {
String[] parts = list.split("" + ((char)10));
File[] files = new File[parts.length];
for(int i = 0 ; i < parts.length; i++) {
files[i] = new File(root + File.separatorChar + parts[i]);
}
dirContent = files;
fileChooser.setCurrentDirectory(new File(root));
fileChooser.updateUI();
auto = true;
}
don't to call fileChooser.updateUI(); this is for apply custom UI or to change methods from Look and Feel
I think that better could be to use JList, or JTree as FileSystemView, then to create new File, Folder e.i. programatically
examples here
After browsing other JFileChooser projects I found method
fileChooser.rescanCurrentDirectory();
which seems to update file system view..
everytime I ask a question I find answer shortly after :/

Categories

Resources