@Override
    public long writeData(final InputStream data) throws IOException, ResourceModelSourceException {
        if (!isDataWritable()) {
            throw new IllegalArgumentException("Cannot write to file, it is not configured to be writeable");
        }
        ResourceFormatParser resourceFormat = getResourceFormatParser();
        //validate data
        File temp = Files.createTempFile("temp", "." + resourceFormat.getPreferredFileExtension()).toFile();
        temp.deleteOnExit();


        try {

            try (FileOutputStream fos = new FileOutputStream(temp)) {
                Streams.copyStream(data, fos);
            }
            final ResourceFormatParser parser = getResourceFormatParser();
            try {
                final INodeSet set = parser.parseDocument(temp);
            } catch (ResourceFormatParserException e) {
                throw new ResourceModelSourceException(e);
            }
            try (FileInputStream tempStream = new FileInputStream(temp)) {
                return writeFileData(tempStream);
            }
        } finally {
            temp.delete();
        }
    }
@ Override public long writeData ( final InputStream data ) throws IOException , ResourceModelSourceException { if ( ! isDataWritable ( ) ) { throw new IllegalArgumentException ( "Cannot write to file, it is not configured to be writeable" ) ; } ResourceFormatParser resourceFormat = getResourceFormatParser ( ) ; File temp = Files . createTempFile ( "temp" , "." + resourceFormat . getPreferredFileExtension ( ) ) . toFile ( ) ; temp . deleteOnExit ( ) ; try { try ( FileOutputStream fos = new FileOutputStream ( temp ) ) { Streams . copyStream ( data , fos ) ; } final ResourceFormatParser parser = getResourceFormatParser ( ) ; try { final INodeSet set = parser . parseDocument ( temp ) ; } catch ( ResourceFormatParserException e ) { throw new ResourceModelSourceException ( e ) ; } try ( FileInputStream tempStream = new FileInputStream ( temp ) ) { return writeFileData ( tempStream ) ; } } finally { temp . delete ( ) ; } }
Writes the data to a temp file, and attempts to parser it, then if successful it will
call {@link #writeFileData(InputStream)} to invoke the sub class

@param data data

@return number of bytes written

@throws IOException                  if an IO error occurs
@throws ResourceModelSourceException if an error occurs parsing the data.