Package uk.org.ogsadai.activity.io

Examples of uk.org.ogsadai.activity.io.BlockWriter


    {
        try
        {
            preprocess();
            BlockReader data = getInput(INPUT_DATA);
            BlockWriter result = getOutput();
            int arraySize = getArraySize();
           
            BytesOutputStream bytes =
                new BytesOutputStream(result, arraySize);

            STypeOutputStream output = new STypeOutputStream(bytes);
            result.write(ControlBlock.LIST_BEGIN);
            Object block;
            while ((block = data.read()) != ControlBlock.NO_MORE_DATA)
            {
                serialise(data, output, block);
            }
            output.close();
            result.write(ControlBlock.LIST_END);
        }
        catch (IOException e)
        {
            throw new ActivityProcessingException(e);
        }
View Full Code Here


            ActivityProcessingException, ActivityTerminatedException
    {
        preprocess();
       
        BlockReader data = getInput(INPUT_DATA);
        BlockWriter result = getOutput(OUTPUT_RESULT);
       
        try
        {
           
            // make sure we have a list of binary data
            // BytesInputStream expects that the LIST_BEGIN has been read
            Object first = data.read();
            if (first != ControlBlock.LIST_BEGIN)
            {
                throw new InvalidInputValueException(INPUT_DATA, first);
            }
           
            BytesInputStream bytes = new BytesInputStream(INPUT_DATA, data);
            STypeInputStream input = new STypeInputStream(bytes);
           
            // code block below throws :
            // - EOFException when the end of the data has been reached or
            // - another exception if there was a problem reading the data
            while (true)
            {
                Object block = input.read();
                if (block instanceof ObjectInputStream)
                {
                    ObjectInputStream obj = (ObjectInputStream) block;
                    ObjectSerialiser ser = mSerialisers.getSerialiser(obj.getType());
                    if (ser == null)
                    {
                        LOG.debug("No serialiser for type: " + obj.getType());
                        throw new ActivityProcessingException(
                                new MissingSerialiserException(obj.getType()));
                    }
                    ser.deserialise(obj.getInput(), result);
                }
                else
                {
                    result.write(block);
                }
            }
           

        }
View Full Code Here

            int i = 0;
            String[] out = null;
            out = last.split(" ");
            for (Object object : mOutputs)
            {
                BlockWriter output = (BlockWriter)object;
                output.write(out[i++]);
            }
        }
        catch (IOException e)
        {
            throw new ActivityProcessingException(e);
View Full Code Here

    //String staTime =(String) iterationData[3];
    //String endTime =(String) iterationData[4];
    mMetadataOutputBlockWriter = getOutput(METADATA);
    ListIterator parameters=(ListIterator) iterationData[0];
    parametersMap=extractParameters(parameters);
    BlockWriter output = getOutput();
    ArrayList<File> fileList=new ArrayList<File>();
    try {
    String homeDir=mResource.getHomeDirectory().getAbsolutePath()
    final String station=(String) parametersMap.get(STATION);
    String channel=(String) parametersMap.get(CHANNEL);
    
    Calendar eCal=GregorianCalendar.getInstance();
    Calendar sCal=GregorianCalendar.getInstance();
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    Date sDate=dateFormatter.parse((String)parametersMap.get(START_TIME));
    Date eDate=dateFormatter.parse((String)parametersMap.get(END_TIME));
    sCal.setTime(sDate);
    eCal.setTime(eDate);
    StringBuffer dirName=new StringBuffer();
    File homeDirectory=mResource.getHomeDirectory();
    File[] stationDir=homeDirectory.listFiles(
    new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.contains(station);
         
        };
    });
   
    if (stationDir.length==0 || !stationDir[0].exists()||!stationDir[0].isDirectory())
    {           
          System.out.println("station: "+station+" not found");
          outmap.put(ERROR,"station: "+station+" not found");
        throw new ActivityUserException(new Throwable("station: "+station+" not found"));
    }
     // dirName.append(stationDir[0].getPath()).append(File.separatorChar);
      String stationPath=stationDir[0].getPath().substring(homeDir.length());
   
      while(eCal.compareTo(sCal)>=0){
       
         dirName.append(stationPath).append(File.separatorChar)
          .append(eCal.get(Calendar.YEAR)).append(File.separatorChar)
          .append(String.format("%tm", eCal));
         String dName=dirName.toString();
          dirName.setLength(0);
     //     System.out.println("dirname: "+dName);
          File directory = mResource.getFileForReading(dName);
       //   System.out.println("directory check: "+directory.getAbsolutePath());
        if (!directory.exists())
      {           
      System.out.println(dName+" "+" DIRECTORY_NOT_FOUND");
      eCal.add(Calendar.MONTH, - 1);
      continue;
      }
      else if (!directory.isDirectory())
      {
          throw new ActivityUserException(ErrorID.NOT_A_DIRECTORY);
      }
   
      File[] files = directory.listFiles(new WFileFilter(dateFormatter.format(eCal.getTime()), "",station.toUpperCase(), channel.toUpperCase()));
       
      for(File file:files)
      {
        System.out.println("adding file: "+file.getName());
        fileList.add(file);
      }  
    
         eCal.add(Calendar.DAY_OF_MONTH, - 1);
     
     
   

      output.write(ControlBlock.LIST_BEGIN);
     
     
     
    for (Iterator<File> it = fileList.iterator(); it.hasNext();)
    {
     
      String outFile=it.next().getAbsolutePath().substring(homeDir.length());
      System.out.println("file: "+outFile);
        output.write(outFile );
    }
    output.write(ControlBlock.LIST_END)
 
    }catch (ActivityUserException ae) {
      try {
        output.write(ControlBlock.LIST_BEGIN);
        output.write("");
        output.write(ControlBlock.LIST_END);

        } catch (PipeClosedException e)
          {
              iterativeStageComplete();
          }
View Full Code Here

    //String network= (String) iterationData[0];
    //String station =(String) iterationData[1];
    //String channel =(String) iterationData[2];
    ListIterator parameters=(ListIterator) iterationData[0];
    HashMap<String,String> paramsMap=extractParameters(parameters);
    BlockWriter output = getOutput();
    ArrayList<File> fileList = new ArrayList<File>();
    try {
     String homeDir=mResource.getHomeDirectory().getAbsolutePath()
     String network=paramsMap.get(NETWORK);
     String station=paramsMap.get(STATION);
     String channel=paramsMap.get(CHANNEL);
     Calendar eCal=GregorianCalendar.getInstance();
     Calendar sCal=GregorianCalendar.getInstance();
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd")
     //System.out.println("sDate: "+staTime);
     //System.out.println("eDate: "+endTime);
     Date sDate = dateFormatter.parse(paramsMap.get(START_TIME));   
     Date eDate=dateFormatter.parse(paramsMap.get(END_TIME));
     sCal.setTime(sDate);
     eCal.setTime(eDate);
    // System.out.println("sDay: "+sCal.get(Calendar.DAY_OF_YEAR));
     //System.out.println("eDay: "+eCal.get(Calendar.DAY_OF_YEAR));
    
     StringBuffer dirName=new StringBuffer();
     while(eCal.compareTo(sCal)>=0){
         dirName.append(eCal.get(Calendar.YEAR)).append(File.separatorChar).append(String.format("%tj", eCal));
           String dName=dirName.toString();
           dirName.setLength(0);
           System.out.println("dirName: "+homeDir+" "+dName);
           File directory = mResource.getFileForReading(dName);
           if (!directory.exists())
        {           
          
              System.out.println(dName+" DIRECTORY_NOT_FOUND");
              eCal.add(Calendar.DAY_OF_YEAR, - 1);
          continue;
        }
        else if (! directory.isDirectory())
        {
             outmap.put(ERROR,ErrorID.NOT_A_DIRECTORY);
             
          throw new ActivityUserException(ErrorID.NOT_A_DIRECTORY);
        }
     
        File[] files = directory.listFiles(new WFileFilter(String.format("%tY", eCal),network.toUpperCase() ,station.toUpperCase(), channel.toUpperCase()));
       
        for(File file:files)
        {
          System.out.println("adding file: "+file.getName());
          fileList.add(file);
       
      
           eCal.add(Calendar.DAY_OF_YEAR, - 1);
       
       
       
     
    //  } catch (FileResourceUseException e) {
      //   e.printStackTrace();
        
       
    //  }
        //  try {
           
        output.write(ControlBlock.LIST_BEGIN);
     
      for (Iterator<File> it = fileList.iterator(); it.hasNext();)
      {
        String outFile=it.next().getAbsolutePath().substring(homeDir.length());
       
          output.write(outFile );
      }
      output.write(ControlBlock.LIST_END);
       
        } catch (ParseException e) {
        throw new ActivityUserException(e);
     
          } catch (PipeClosedException e)
View Full Code Here

    final String station=paramsMap.get(STATION);
    final String channel=paramsMap.get(CHANNEL);
    System.out.println("in RespReaderaActivity");
   
   
    BlockWriter output = getOutput();
    try {
      File homeDirectory=mResource.getHomeDirectory();
      File[] respFiles=homeDirectory.listFiles(
      new FilenameFilter() {
          public boolean accept(File dir, String name) {
              return ((network!=null&&!"".equals(network))?name.contains(network):true)&&name.contains(station)&&name.contains(channel);
          };
      });
      List <Tuple> tuples=new ArrayList<Tuple>();
      if(respFiles.length==0){
           //   throw new  ActivityUserException(new Throwable("response file not available"));
      System.out.println("response file not available");
     
      }
      else{
      ResponsePAZ resPAZ=parseResp(respFiles[0]);
   
      //List <Tuple> tuples=new ArrayList<Tuple>();
      //for(ResponsePAZ resPAZ:res){
        Tuple t= makeTuple(resPAZ.getName(),resPAZ.getGain(),resPAZ.getGainFreq(),new SimpleBlob(prettyPrintComplex(resPAZ.getZeros())),new SimpleBlob(prettyPrintComplex(resPAZ.getPoles())));
            tuples.add(t);
      }
          MetadataWrapper metadataWrapper=new MetadataWrapper(makeTupleMetadata(new String[]{ NAME, GAIN,GAIN_FREQUENCY,ZEROS,POLES},
                      new int[] { TupleTypes._STRING, TupleTypes._DOUBLE,TupleTypes._DOUBLE,TupleTypes._ODBLOB,TupleTypes._ODBLOB }));
      //}  
      // Object[] responseTuple = new Object[]{
            output.write(ControlBlock.LIST_BEGIN);
            output.write(metadataWrapper);
            for(Tuple tu:tuples)
                     output.write(tu);                
      
            output.write(ControlBlock.LIST_END);
     
       
        //output.write(ControlBlock.LIST_BEGIN);
     
     
View Full Code Here

      TupleMetadata tupleMetadata = (TupleMetadata) metadataWrapper.getMetadata();
      Tuple tuple;
    try {
     
     mOutputBlockWriter = getOutput(OUTPUT_DATA);
       BlockWriter meanOut = getOutput(MEAN);
       mMetadataOutputBlockWriter = getOutput(METADATA);
       List<ResponsePAZ> responses=new ArrayList<ResponsePAZ>()
       int i=0;
       parametersMap = new HashMap<String,String>();
       while((tuple= (Tuple)tupleListIterator.nextValue())!= null){
         System.out.println("in iteration tuple");
        ResponsePAZ response= new ResponsePAZ();
        response.setName(tuple.getString(tupleMetadata,NAME));
        response.setGain(tuple.getDouble(tupleMetadata,GAIN));
        response.setGainFreq(tuple.getDouble(tupleMetadata,GAIN_FREQUENCY));
          Blob zerosB=tuple.getBlob(tupleMetadata,ZEROS);
          Blob polesB=tuple.getBlob(tupleMetadata,POLES);
        response.setZeros(zerosB.getBytes(1, (int) zerosB.length()));
          response.setPoles(polesB.getBytes(1, (int) polesB.length()));
      responses.add(response);
      JSONSerializer serializer = new JSONSerializer();
      parametersMap.put("response"+i, URLEncoder.encode(serializer.serialize(response),"UTF-8"));
      i++;
       }
    //   String homePath=mResource.getHomeDirectory().getAbsolutePath();
      //fileName=homePath+"/"+fileName;
    //   if(fileName!=null&&!"".equals(fileName))
       outmap=(HashMap)((AbstractInstrumentCorrection)this.userDefinedProcess).removeInstrument(fileName, responses, this.getActivityDescriptor().getInstanceName().getLocalPart()+count, "/","/");
       mOutputBlockWriter.write((String)outmap.get( OUTPUT_DATA));
     meanOut.write(ControlBlock.LIST_BEGIN);
       meanOut.write((String)outmap.get(MEAN));
       meanOut.write(ControlBlock.LIST_END);
    } catch (FileResourceUseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
View Full Code Here

      ActivityUserException {
   
    String staTime =(String) iterationData[0];
    String endTime =(String) iterationData[1];
    Integer duration=((Number)iterationData[2]).intValue();
    BlockWriter intervalsWriter = getOutput(INTERVALS_OUTPUT);
    BlockWriter iterationsWriter = getOutput(ITERATIONS_OUTPUT);
    List<String> intervalsList = new ArrayList<String>();
    try {
     Calendar eCal=GregorianCalendar.getInstance();
     Calendar sCal=GregorianCalendar.getInstance();
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
     System.out.println("sDate: "+staTime);
     System.out.println("eDate: "+endTime);
     Date sDate = dateFormatter.parse(staTime);
       Date eDate = dateFormatter.parse(endTime);
     sCal.setTime(sDate);
     eCal.setTime(eDate);
     //StringBuffer
     while(sCal.compareTo(eCal)<0){
      String sti=dateFormatter.format(sCal.getTime());
      sCal.add(Calendar.HOUR_OF_DAY, duration.intValue());
      String eti;
      if(sCal.compareTo(eCal)>0)
        eti=dateFormatter.format(eCal.getTime());
      else
          eti=dateFormatter.format(sCal.getTime());
      intervalsList.add(START_TIME+"="+sti);
      intervalsList.add(END_TIME+"="+eti);
      System.out.println("sti: "+sti);
      System.out.println("eti: "+eti);
     }
    /* if(sCal.compareTo(eCal)!=0){
      String sti=dateFormatter.format(sCal.getTime());
      String eti=dateFormatter.format(eCal.getTime());
      intervalsList.add(START_TIME+"="+sti);
      intervalsList.add(END_TIME+"="+eti);
     }*/
     System.out.println("beginning to write output");
     for(int i=0;i<intervalsList.size()-1;i=i+2){
       intervalsWriter.write(ControlBlock.LIST_BEGIN);
       intervalsWriter.write(intervalsList.get(i));
       intervalsWriter.write(intervalsList.get(i+1));
       intervalsWriter.write(ControlBlock.LIST_END);
       }   
     System.out.println("end first block");
     iterationsWriter.write(intervalsList.size()/2);
    
    } catch (ParseException e) {
      throw new ActivityUserException(e);
    } catch (PipeClosedException e) {
       iterativeStageComplete();
View Full Code Here

    try{
   
      Object data =  iterationData[0];
      Object metadata = iterationData[1];
   
    BlockWriter outputWriter = getOutput(OUTPUT);
    
    
    
    outputWriter.write(ControlBlock.LIST_BEGIN);
    outputWriter.write(metadata);
    outputWriter.write(data);
    outputWriter.write(ControlBlock.LIST_END);
    
    
    } catch (PipeClosedException e) {
       iterativeStageComplete();
    } catch (PipeIOException e) {
View Full Code Here

      ActivityUserException {
    try{
   
    
    ListIterator dataMetadata =  (ListIterator)iterationData[0];
    BlockWriter outputDataWriter = getOutput(DATA);
    BlockWriter outputMetadataWriter = getOutput(METADATA);
    String info;
   
     // extract activity parameters
     while( (info = (String)dataMetadata.nextValue()) != null)
       {
           outputMetadataWriter.write(info);
             info = (String)dataMetadata.nextValue();
         outputDataWriter.write(info);
        
 
       }
View Full Code Here

TOP

Related Classes of uk.org.ogsadai.activity.io.BlockWriter

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.