Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SbgnUtil.readFrom(InputStream is) fails when conversion from Milestone 1 or 2 necessary #49

Open
tczauderna opened this issue May 22, 2019 · 2 comments
Labels

Comments

@tczauderna
Copy link
Collaborator

SbgnUtil.readFrom(InputStream is) fails when a conversion is necessary (from Milestone 1 or 2).

The problem is that the input stream can only be used once.

This happens here
Sbgn result = (Sbgn) unmarshaller.unmarshal(is);

Afterwards the input stream is closed and a conversion is not possible.

This will always fail
String docUri = XmlUtil.getDocumentUri(is);

Possible fixes

  1. Don't provide conversion when an input stream is used. There is other readFrom methods which don't provide a conversion.
  2. Save the input stream to a file and use readFromFile
public static Sbgn readFrom(InputStream is) throws IOException, JAXBException {
	
	try {
		File tmp = File.createTempFile("sbgn-", ".sbgn");
		tmp.deleteOnExit();
		Files.copy(is, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
		return readFromFile(tmp);
	} catch (IOException ex) {
		throw ex;
	}
}
@fbergmann
Copy link
Contributor

thanks for letting me know, I have to say i was really surprised how hard it seems to be to get the namespace uri's in Java. I'll have a look ... maybe there should be an option on SbgnUtil that controls whether a conversion should be attempted or not, and only if perform the workaround. I'll think about it

@fbergmann
Copy link
Contributor

added test code, and unified the way non-files are treated, i hope this resolves the issue.

@tczauderna tczauderna added the bug label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants