[FIXED] Importing from String instead of File

Get help with your data
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
User avatar
ppareja
Posts:10
Joined:15 Apr 2011 10:31
Location:Granada, Spain
Contact:
[FIXED] Importing from String instead of File

Post by ppareja » 24 Apr 2011 15:23

Hi all,

I don't find the way to import a gexf model from a String instead of from a File.
The class ImportController does not seem to expose such a method, is there any other class/method I could use for this purpose?
Thanks in advance,

Pablo

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Importing from String instead of File

Post by mbastian » 24 Apr 2011 23:24

Import controller can import from InputStream and Reader, in the same way than files. However, it can't automatically guess what format you are using, as there is no file extension, so you have to provide the appropriate importer. The GEXF importer can simply be retrieved using the getFileImporter() method.

Code: Select all

ImportController importController = Lookup.getDefault().lookup(ImportController.class);
String str = ...
StringReader reader = new StringReader(str);
Container c = importController.importFile(reader, importController.getFileImporter("gexf"));

User avatar
ppareja
Posts:10
Joined:15 Apr 2011 10:31
Location:Granada, Spain
Contact:

Re: Importing from String instead of File

Post by ppareja » 25 Apr 2011 10:59

Ok, thanks a lot.

Pablo

User avatar
ppareja
Posts:10
Joined:15 Apr 2011 10:31
Location:Granada, Spain
Contact:

Re: Importing from String instead of File

Post by ppareja » 25 Apr 2011 11:27

Hi again,

I just tried your piece of code and the statement:

Code: Select all

importController.getFileImporter("gexf")
returns null,
why's that?

I'm using version 0.7.2014

Cheers,

Pablo

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Importing from String instead of File

Post by mbastian » 25 Apr 2011 22:07

That should work, but I looked at the code we are actually checking for the extension, so do that

Code: Select all

importController.getFileImporter(".gexf")
and it should work. I will report a bug, as having both matching is expected.

User avatar
ppareja
Posts:10
Joined:15 Apr 2011 10:31
Location:Granada, Spain
Contact:

Re: Importing from String instead of File

Post by ppareja » 26 Apr 2011 11:02

Hi Bastian,

I just tried that fix and it works fine now, thanks ;)

Pablo

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable