Package genj.io

Examples of genj.io.SniffedInputStream


    LOG.finest("Generating GIG into file: "+generatedGigFile+" while reading from file: "+origin);

    generatedGigFile.getParentFile().mkdirs();
    FileOutputStream fos = new FileOutputStream(generatedGigFile);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    SniffedInputStream inStream = new SniffedInputStream(origin.open());
    //String encoding = inStream.getEncoding();
    Charset charset = inStream.getCharset();

    if (inStream.getWarning()!=null)
    {
      LOG.warning(inStream.getWarning());
    }

    String charsetName = EnvironmentChecker.getProperty(this, "genj.gedcom.charset", null, "checking for forced charset for read of inputStream");
    if (charsetName!=null) {
      try {
        charset = Charset.forName(charsetName);
        //encoding = Gedcom.UTF8;
      } catch (Throwable t) {
        LOG.log(Level.WARNING, "Can't force charset "+charset, t);
      }
    }

    OutputStreamWriter out = new OutputStreamWriter(bos, charset);
    InputStreamReader in = new InputStreamReader(inStream, charset);
    GigPullHandler handler = new GigPullHandler();
    handler.setInsertDelta(1);
    handler.setToName(toName);
    handler.setToURL(toURL);
    handler.setToRelation(toRelValue);
    handler.setFromRelation(fromRelValue);
    handler.setOutWriter(out);
   
    GLinkPattern pattern = new GLinkPattern("0 @"+fromURL.getIndividualId()+"@ INDI");
    pattern.setCompareSize(pattern.getToMatch().length()+10);
    pattern.setNumberOfMatches(1);
   
    GLinkPullParser pullParser = new GLinkPullParser();
    //pullParser.setWriter(out);
    pullParser.setReader(in);
    pullParser.addPullHander(pattern, handler);
    pullParser.parse();
   
    out.flush();
    out.close();
    bos.flush();
    bos.close();
    fos.flush();
    fos.close();
    in.close();
    inStream.close();
   
    //genj.io.GedcomPullParser or something like that; being able to pass in the Origin and an OutputStream and
    //an implementation of the GedcomPullHandler interface
    //if the OutputStream is not null then the Characters that get parsed are written to the OutputStream and
    //so the invoker must indicate at which Character the GedcomPullHandler will get invoked using a pattern matching
View Full Code Here


    //Origin origin = Origin.create(filename, new Handler());
    LOG.finest("Generating GEG into file: "+generatedGegFile+" while reading from file: "+glinkXMLURL);
   
    //String encoding = "UTF-8";//inStream.getEncoding();
    //Charset charset = Charset.forName(encoding);//inStream.getCharset();
    SniffedInputStream inStream = new SniffedInputStream(in);
    //String encoding = inStream.getEncoding();
    Charset charset = inStream.getCharset();

    if (inStream.getWarning()!=null)
    {
      LOG.warning(inStream.getWarning());
    }

    String charsetName = EnvironmentChecker.getProperty(this, "genj.gedcom.charset", null, "checking for forced charset for read of inputStream");
    if (charsetName!=null) {
      try {
        charset = Charset.forName(charsetName);
        //encoding = Gedcom.UTF8;
      } catch (Throwable t) {
        LOG.log(Level.WARNING, "Can't force charset "+charset, t);
      }
    }
   
   
        InputStreamReader inReader = new InputStreamReader(inStream, charset);
        generatedGegFile.getParentFile().mkdirs();
    FileOutputStream fos = new FileOutputStream(generatedGegFile);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
        OutputStreamWriter out = new OutputStreamWriter(bos, charset);
   
    // 2) find a way to do a pull parser of the xml stream;
    //    looking for patterns which indicate where to insert the new GLink

        // TODO: now read in from the InputStream 'in' and look for the pattern and write to generatedGegFile
    GLinkPattern pattern = new GLinkPattern("</g:glinks>");
    pattern.setCompareSize(pattern.getToMatch().length());
    pattern.setNumberOfMatches(1);
   
    GegPullHandler handler = new GegPullHandler();
    handler.setInsertDelta( - (pattern.getToMatch().length()) - 5);
    handler.setToName(toName);
    handler.setToURL(toURL);
    handler.setToRelation(toRelValue);
    handler.setFromRelation(fromRelValue);
    handler.setOutWriter(out);
    handler.setAuthenticated(authenticated);

    GLinkPullParser pullParser = new GLinkPullParser();
    //pullParser.setOutputStream(bos);
    //pullParser.setInputStream(in);
    pullParser.setReader(inReader);
    pullParser.addPullHander(pattern, handler);
    pullParser.parse();
    inStream.close();
    inReader.close();
    in.close();
    out.flush();
    out.close();
    bos.flush();
View Full Code Here

TOP

Related Classes of genj.io.SniffedInputStream

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.