Search in sources :

Example 1 with IMapInputStreamConverter

use of org.freeplane.features.url.IMapInputStreamConverter in project freeplane by freeplane.

the class MFileManager method loadTreeImpl.

private NodeModel loadTreeImpl(final MapModel map, final File f) throws FileNotFoundException, IOException, XMLException, MapConversionException {
    final BufferedInputStream file = new BufferedInputStream(new FileInputStream(f));
    int versionInfoLength = 1000;
    final byte[] buffer = new byte[versionInfoLength];
    final int readCount = file.read(buffer);
    final String mapStart = new String(buffer, FileUtils.defaultCharset().name());
    final ByteArrayInputStream readBytes = new ByteArrayInputStream(buffer, 0, readCount);
    final InputStream sequencedInput = new SequenceInputStream(readBytes, file);
    Reader reader = null;
    MapVersionInterpreter versionInterpreter = MapVersionInterpreter.getVersionInterpreter(mapStart);
    map.addExtension(versionInterpreter);
    if (versionInterpreter.anotherDialect) {
        String message = versionInterpreter.getDialectInfo(f.getAbsolutePath());
        UITools.showMessage(message, JOptionPane.WARNING_MESSAGE);
    }
    if (versionInterpreter.needsConversion) {
        final int showResult = OptionalDontShowMeAgainDialog.show("really_convert_to_current_version", "confirmation", MMapController.RESOURCES_CONVERT_TO_CURRENT_VERSION, OptionalDontShowMeAgainDialog.ONLY_OK_SELECTION_IS_STORED);
        IMapInputStreamConverter isConverter = versionInterpreter.getMapInputStreamConverter();
        if (showResult != JOptionPane.OK_OPTION || isConverter == null) {
            reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
        } else {
            sequencedInput.close();
            // reader = UrlManager.getUpdateReader(f, FREEPLANE_VERSION_UPDATER_XSLT);
            reader = isConverter.getConvertedStream(f);
        }
    } else {
        reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
    }
    try {
        return Controller.getCurrentModeController().getMapController().getMapReader().createNodeTreeFromXml(map, reader, Mode.FILE);
    } finally {
        FileUtils.silentlyClose(reader);
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) MapVersionInterpreter(org.freeplane.features.url.MapVersionInterpreter) IMapInputStreamConverter(org.freeplane.features.url.IMapInputStreamConverter)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 SequenceInputStream (java.io.SequenceInputStream)1 IMapInputStreamConverter (org.freeplane.features.url.IMapInputStreamConverter)1 MapVersionInterpreter (org.freeplane.features.url.MapVersionInterpreter)1