Разработка контента курса дистанционного обучения "DB2 универсальная база данных", страница 48

            Context ctx = new InitialContext(env);

            Object ejbHome = ctx.lookup("REPLICATOR");

            ReplicatorHome replicatorHome = (ReplicatorHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object) ejbHome, ReplicatorHome.class);

            Replicator replicator = replicatorHome.create();

            replicator.proceedReplication(rowSet.rows);

        } catch(Exception ex){

            ex.printStackTrace(System.out);

        }

    }

}

Part.java

public class Part {

      private String name = null;

      private String value = null;

      private int startIndex = -1;

      private int stopIndex = -1;

      Part( String xName, String xValue ){

            name = xName;

            value = xValue;

      }

      Part( String xName, int begin, int end ){

            name = xName.substring( xName.lastIndexOf( "\\" )+1 );

            startIndex = begin;

            stopIndex = end;

      }

      public boolean isFile(){

            if( value == null ){

                  return true;

            }

            return false;

      }

      public String getName(){

            return name;

      }

      public String getValue(){

            if( value != null ){

                  return value;

            }

            return null;

      }

      public int getStartIndex(){

            return startIndex;

      }

      public int getStopIndex(){

            return stopIndex;

      }

}

MultiPartParser.java

import courseExample.ReplicatorHome;

import courseExample.Replicator;

import org.xml.sax.XMLReader;

import org.xml.sax.SAXParseException;

import org.xml.sax.SAXException;

import org.xml.sax.InputSource;

import org.xml.sax.helpers.XMLReaderFactory;

import javax.servlet.ServletInputStream;

import javax.servlet.http.HttpServletRequest;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.ejb.CreateException;

import java.io.*;

import java.util.Hashtable;

public class MultiPartParser {

      private byte[] inBytes = null;

      private String inStr = null;

      private String bounds = null;

      public MultiPartParser(HttpServletRequest request) throws IOException {

            String contentType= request.getHeader( "Content-Type" );

            int size = request.getIntHeader( "Content-Length" );

            if( contentType.indexOf( "multipart/form-data" ) != -1 && contentType.indexOf( "boundary=" ) != -1 && size > 0 && size < 10000000 ){

                bounds = contentType.substring( (contentType.indexOf( "boundary=" ) + "boundary=".length()) );

                bounds = "--" + bounds;

                  int i = 0;

                  int readedByte = -1;

                  inBytes = new byte[size];

                  StringBuffer sb = new StringBuffer();

                  ServletInputStream sis = request.getInputStream();

                  BufferedInputStream bis = new BufferedInputStream( (InputStream)sis );

                  while( ( readedByte = bis.read() ) != -1 ){

                        inBytes[i] = (byte)readedByte;

                        i++;

                        sb.append( (char)readedByte );

                  }

                  inStr = new String( sb );

            }

      }

      public Part[] getAllParts(){

          Part[] returnMe = null;

            int partsCount = 0;

            int temp = -1;

           while( (temp = inStr.indexOf( "Content-Disposition: form-data;", temp + 1 )) != -1 ){

                 temp = temp + "Content-Disposition: form-data;".length() ;

                  partsCount++;

            }

            if( partsCount > 0 ){

                returnMe = new Part[partsCount];

                int startIndex = 0;

                int stopIndex = 0 - bounds.length() - 1;

                temp = -1;

                boolean isFile = false;

                String name = null;