Package org.apache.xmlbeans.impl.piccolo.io

Examples of org.apache.xmlbeans.impl.piccolo.io.FileFormatException


  public static void importDb(String appcode,ZipInputStream zis) throws FileFormatException,Exception{
    String fileContent = null;
      try{
        //get the zipped file list entry
        ZipEntry ze = zis.getNextEntry();
        if (ze==null) throw new FileFormatException("Looks like the uploaded file is not a valid export.");
        if(ze.isDirectory()){
          ze = zis.getNextEntry();
        }
        if(ze!=null){
          File newFile = File.createTempFile("export",".json");
          FileOutputStream fout = new FileOutputStream(newFile);
          for (int c = zis.read(); c != -1; c = zis.read()) {
            fout.write(c);
          }
          fout.close();
          fileContent = FileUtils.readFileToString(newFile);
          newFile.delete();
        }else{
          throw new FileFormatException("Looks like the uploaded file is not a valid export.");
        }
        ZipEntry manifest = zis.getNextEntry();
        if(manifest!=null){
          File manifestFile = File.createTempFile("manifest",".txt");
          FileOutputStream fout = new FileOutputStream(manifestFile);
          for (int c = zis.read(); c != -1; c = zis.read()) {
            fout.write(c);
          }
          fout.close();
          String manifestContent  = FileUtils.readFileToString(manifestFile);
          manifestFile.delete();
          Pattern p = Pattern.compile(BBInternalConstants.IMPORT_MANIFEST_VERSION_PATTERN);
          Matcher m = p.matcher(manifestContent);
          if(m.matches()){
            String version = m.group(1);
            if (version.compareToIgnoreCase("0.6.0")<0){ //we support imports from version 0.6.0
              throw new FileFormatException(String.format("Current baasbox version(%s) is not compatible with import file version(%s)",BBConfiguration.getApiVersion(),version));
            }else{
              if (Logger.isDebugEnabled()) Logger.debug("Version : "+version+" is valid");
            }
          }else{
            throw new FileFormatException("The manifest file does not contain a version number");
          }
        }else{
          throw new FileFormatException("Looks like zip file does not contain a manifest file");
        }
        if (Logger.isDebugEnabled()) Logger.debug("Importing: "+fileContent);
        if(fileContent!=null && StringUtils.isNotEmpty(fileContent.trim())){
          DbHelper.importData(appcode, fileContent);
          zis.closeEntry();
          zis.close();
        }else{
          throw new FileFormatException("The import file is empty");
        }
      }catch(FileFormatException e){
        Logger.error(e.getMessage());
        throw e;
      }catch(Throwable e){
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.impl.piccolo.io.FileFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.