Ejemplo n.º 1
0
  public final boolean unify(final JIPCons params, Hashtable varsTbl) {
    JIPTerm output = params.getNth(1);
    JIPTerm term = params.getNth(2);

    // check if input is a variable
    if (output instanceof JIPVariable) {
      // try to extract the term
      if (!((JIPVariable) output).isBounded()) {
        throw new JIPInstantiationException(1);
      } else {
        // extracts the term
        output = ((JIPVariable) output).getValue();
      }
    }

    // Get the stream
    StreamInfo sinfo = JIPio.getOutputStreamInfo(output, false);

    //        String mode = sinfo.getProperties().getProperty("mode");
    //        if(!(mode.equals("mode(write)") || mode.equals("mode(append)")))
    //        	throw new JIPPermissionException("output", "stream", sinfo.getAlias());
    //        if(!sinfo.getProperties().getProperty("type").equals("type(text)"))
    //        	throw new JIPPermissionException("output", "binary_stream", sinfo.getAlias());

    OutputStream writer = JIPio.getOutputStream(sinfo.getHandle(), getJIPEngine());

    try {
      writer.write(term.toString(getJIPEngine()).getBytes(getJIPEngine().getEncoding()));
      writer.flush();
    } catch (IOException ex) {
      throw new JIPRuntimeException(JIPio.ERR_IOEXCEPTION, ex.getMessage());
    }

    return true;
  }
Ejemplo n.º 2
0
  public static RecordingInfo getRecordingInfo(int number) throws IOException {
    Response response = VDRConnection.send(new LSTR(number));
    if (response != null && response.getCode() == 215) {
      try {
        org.hampelratte.svdrp.responses.highlevel.Recording rec = new Recording();
        new RecordingParser().parseRecording(rec, response.getMessage());

        RecordingInfo recordingInfo = new RecordingInfo();
        recordingInfo.id = MD5.calculate(response.getMessage());

        recordingInfo.channelName = rec.getChannelName();
        recordingInfo.date = rec.getStartTime().getTimeInMillis() / 1000;
        recordingInfo.description = rec.getDescription();
        long end = rec.getEndTime().getTimeInMillis() / 1000;
        recordingInfo.duration = end - recordingInfo.date;
        recordingInfo.title = rec.getDisplayTitle();
        recordingInfo.priority = rec.getPriority();
        recordingInfo.lifetime = rec.getLifetime();

        for (Stream stream : rec.getStreams()) {
          StreamInfo si = new StreamInfo();
          // stream type
          si.type = Integer.toString(stream.getType(), 16);

          // stream language
          si.language = stream.getLanguage();

          // stream description
          si.description = stream.getDescription();

          // stream kind
          switch (stream.getContent()) {
            case MP2V:
            case H264:
              si.kind = 1;
              recordingInfo.setVideoStream(si);
              break;
            case MP2A:
            case AC3:
            case HEAAC:
              si.kind = 2;
              recordingInfo.addAudioStream(si);
              break;
          }
        }
        return recordingInfo;
      } catch (ParseException e) {
        logger.error("Couldn't get recording info", e);
        throw new IOException(e.getMessage());
      } catch (Exception e) {
        // --- Parser could throw NPE ---
        logger.error("Couldn't get recording info", e);
        throw new IOException("Invalid recording info");
      }
    } else {
      throw new IOException(
          response.getCode() + " - " + response.getMessage().replaceAll("\n$", ""));
    }
  }
  @Override
  public AggregationInfo chronology(String dir, String targetFile) throws IOException {
    log.info("Try to aggregate {} into file {}", dir, targetFile);
    Collection<Hessian2Input> inputStreams = new ArrayList<Hessian2Input>();
    Set<String> fileNameList = fileStorage.getFileNameList(dir);
    if (fileNameList.isEmpty()) {
      log.info("Nothing to aggregate. Directory {} is empty.", dir);
      new Hessian2Output(fileStorage.create(targetFile)).close();
      return new AggregationInfo(0, 0, 0);
    }
    for (String fileName : fileNameList) {
      try {
        InputStream in = fileStorage.open(fileName);
        inputStreams.add(new Hessian2Input(in));
      } catch (FileNotFoundException e) {
        log.warn(e.getMessage(), e);
      }
    }

    int count = 0;
    long minTime = 0;
    long maxTime = 0;

    Hessian2Output out = null;
    OutputStream os = null;
    try {
      if (fileStorage.delete(targetFile, false)) {
        log.warn("Target file {} did not deleted!", targetFile);
      }
      os = fileStorage.create(targetFile);
      out = new Hessian2Output(os);
      MinMaxPriorityQueue<StreamInfo> queue = MinMaxPriorityQueue.create();
      for (Hessian2Input inputStream : inputStreams) {
        LogEntry logEntry;
        try {
          logEntry = (LogEntry) inputStream.readObject();
        } catch (EOFException e) {
          continue;
        }
        queue.add(new StreamInfo(inputStream, logEntry));
      }

      while (!queue.isEmpty()) {
        StreamInfo<LogEntry> streamInfo = queue.removeFirst();
        out.writeObject(streamInfo.lastLogEntry);

        if (count == 0) {
          minTime = streamInfo.lastLogEntry.getTime();
          maxTime = streamInfo.lastLogEntry.getTime();
        } else {
          maxTime = streamInfo.lastLogEntry.getTime();
        }

        count++;
        LogEntry logEntry;
        try {
          logEntry = (LogEntry) streamInfo.stream.readObject();
        } catch (EOFException e) {
          continue;
        }
        streamInfo.lastLogEntry = logEntry;
        queue.add(streamInfo);
      }
    } finally {
      if (out != null) {
        out.close();
        os.close();
      }
    }

    return new AggregationInfo(minTime, maxTime, count);
  }