Ejemplo n.º 1
0
  private void createPlaylist() {
    String showName = MediaFileAPI.GetMediaTitle(mediaFile);
    int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile);
    Log.debug("Number of media file segments: " + numberOfMediaFileSegments);

    for (int i = 0; i < numberOfMediaFileSegments; i++) {
      // get length of current media file segment
      long mediaFileSegmentDurationInMillis = MediaFileAPI.GetDurationForSegment(mediaFile, i);
      long mediaFileSegmentDurationInSeconds =
          mediaFileSegmentDurationInMillis / 1000; // milliseconds to seconds
      Log.debug(
          "mediaFileSegmentDurationInMillis (" + i + "): " + mediaFileSegmentDurationInMillis);
      Log.debug(
          "mediaFileSegmentDurationInSeconds (" + i + "): " + mediaFileSegmentDurationInSeconds);

      int sequence = 0;
      for (int j = 0; j < mediaFileSegmentDurationInSeconds; j += SegmentPlaylist.TARGET_DURATION) {
        long currentDuration =
            Math.min(SegmentPlaylist.TARGET_DURATION, mediaFileSegmentDurationInSeconds - j);

        Segment newSegment = new Segment(currentDuration, sequence, i, showName);

        segmentList.add(newSegment);

        sequence++;
      }
    }
    if (segmentList != null) {
      Log.debug("segmentList size: " + segmentList.size());
    }
  }
Ejemplo n.º 2
0
  public String toString() {
    StringBuilder sb = new StringBuilder();

    String showName = MediaFileAPI.GetMediaTitle(mediaFile);
    int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile);
    int segmentCount = (isFileCurrentlyRecording) ? segmentList.size() - 1 : segmentList.size();
    Log.debug("Show: " + showName);
    Log.debug("MediaFileId: " + mediaFileId);
    Log.debug("Number Of MediaFile segments: " + numberOfMediaFileSegments);
    Log.debug("Is file currently recording: " + isFileCurrentlyRecording);
    Log.debug("Number of playlist segments: " + segmentCount);

    sb.append("#EXTM3U" + LINE_TERM);
    Log.debug("#EXTM3U");
    sb.append("#EXT-X-TARGETDURATION:" + TARGET_DURATION + LINE_TERM);
    Log.debug("#EXT-X-TARGETDURATION:" + SegmentPlaylist.TARGET_DURATION);
    //        sb.append("#EXT-X-MEDIA-SEQUENCE:1" + LINE_TERM);
    //        Log.debug("#EXT-X-MEDIA-SEQUENCE:1");

    for (int i = 0; i < segmentCount; i++) {
      Segment currentSegment = segmentList.get(i);
      Segment previousSegment = (i == 0) ? null : segmentList.get(i - 1);
      Segment nextSegment = (i == segmentCount - 1) ? null : segmentList.get(i + 1);
      String str = currentSegment.toString();
      sb.append(str);

      // first or last playlist segment for each media file segment
      // printing the whole playlist makes the log harder to read
      if ((previousSegment == null)
          || (nextSegment == null)
          || (previousSegment.mediaFileSegment != currentSegment.mediaFileSegment)
          || (currentSegment.mediaFileSegment != nextSegment.mediaFileSegment)) {
        Log.debug(str);
      }
    }

    //      #EXT-X-MEDIA-SEQUENCE:<number>
    //      #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ>
    //      #EXT-X-ALLOW-CACHE:<YES|NO>
    //      #EXT-X-STREAM-INF

    if (!isFileCurrentlyRecording) {
      sb.append("#EXT-X-ENDLIST" + LINE_TERM);
      Log.debug("#EXT-X-ENDLIST");
    }
    return sb.toString();
  }
Ejemplo n.º 3
0
  /**
   * Bind an object to a context ensuring all subcontexts are created if necessary
   *
   * @param ctx the context into which to bind
   * @param name the name relative to context to bind
   * @param obj the object to be bound
   * @exception NamingException if an error occurs
   */
  public static Context bind(Context ctx, String nameStr, Object obj) throws NamingException {
    Name name = ctx.getNameParser("").parse(nameStr);

    // no name, nothing to do
    if (name.size() == 0) return null;

    Context subCtx = ctx;

    // last component of the name will be the name to bind
    for (int i = 0; i < name.size() - 1; i++) {
      try {
        subCtx = (Context) subCtx.lookup(name.get(i));
        if (Log.isDebugEnabled()) Log.debug("Subcontext " + name.get(i) + " already exists");
      } catch (NameNotFoundException e) {
        subCtx = subCtx.createSubcontext(name.get(i));
        if (Log.isDebugEnabled()) Log.debug("Subcontext " + name.get(i) + " created");
      }
    }

    subCtx.rebind(name.get(name.size() - 1), obj);
    if (Log.isDebugEnabled()) Log.debug("Bound object to " + name.get(name.size() - 1));
    return subCtx;
  }
Ejemplo n.º 4
0
  /**
   * 双利理财签约
   *
   * @param context
   * @author sujie
   */
  public void slSign(Context context) {
    try {
      // 查询会计日
      int act = Integer.parseInt(actDate.getCoreActDate());
      Log.debug("------> 核心会计日期:" + act);
      context.setData("actDate", act);
      // 会计日期查询失败
      if (Integer.valueOf(act) == 0) {
        context.setData("resFlag", "E");
        context.setData("resMsg", "签约失败\n\r失败原因:后台获取会计日期失败");
        return;
      }

      // 失效日期
      int endDate = Integer.parseInt((String) context.getData("endDate"));

      if (act <= endDate) {
        // set massage head
        // setHeader(context);

        // set massage body
        setSingMsgBody(context);

        // send to personal gateway
        esbpEcupSender.sendAndReceive(context);

        // response handler
        responseHandler(context);
      } else {
        String actStr = actDate.getCoreActDate();
        String str1 = actStr.substring(0, 4);
        String str2 = actStr.substring(4, 6);
        String str3 = actStr.substring(6);

        actStr = str1 + "年" + str2 + "月" + str3 + "日";
        context.setData("resFlag", "E");
        context.setData("resMsg", "签约失败\n\r失败原因:会计日" + actStr + "必须在截止日期之前");
      }

    } catch (Exception e) {

      logger.error("----->  ShuangliAction Query Exception :  ", e);
      context.setData(ItmFields.RESFLAG, ItmConstants.RESFLAG_ERROR);
      context.setData(ItmFields.RESCODE, ItmRespCode.COMMON_SYSERROR);
    }
  }
Ejemplo n.º 5
0
  /**
   * Construct a resource from a string.
   *
   * @param resource A URL or filename.
   * @param useCaches controls URLConnection caching
   * @return A Resource object.
   */
  public static Resource newResource(String resource, boolean useCaches)
      throws MalformedURLException, IOException {
    URL url = null;
    try {
      // Try to format as a URL?
      url = new URL(resource);
    } catch (MalformedURLException e) {
      if (!resource.startsWith("ftp:")
          && !resource.startsWith("file:")
          && !resource.startsWith("jar:")) {
        try {
          // It's a file.
          if (resource.startsWith("./")) resource = resource.substring(2);

          File file = new File(resource).getCanonicalFile();
          url = file.toURI().toURL();

          URLConnection connection = url.openConnection();
          connection.setUseCaches(useCaches);
          FileResource fileResource = new FileResource(url, connection, file);
          return fileResource;
        } catch (Exception e2) {
          Log.debug(Log.EXCEPTION, e2);
          throw e;
        }
      } else {
        Log.warn("Bad Resource: " + resource);
        throw e;
      }
    }

    // Make sure that any special characters stripped really are ignorable.
    String nurl = url.toString();
    if (nurl.length() > 0
        && nurl.charAt(nurl.length() - 1) != resource.charAt(resource.length() - 1)) {
      if ((nurl.charAt(nurl.length() - 1) != '/'
              || nurl.charAt(nurl.length() - 2) != resource.charAt(resource.length() - 1))
          && (resource.charAt(resource.length() - 1) != '/'
              || resource.charAt(resource.length() - 2) != nurl.charAt(nurl.length() - 1))) {
        return new BadResource(url, "Trailing special characters stripped by URL in " + resource);
      }
    }
    return newResource(url);
  }
Ejemplo n.º 6
0
  /**
   * Construct a resource from a url.
   *
   * @param url the url for which to make the resource
   * @param useCaches true enables URLConnection caching if applicable to the type of resource
   * @return
   */
  public static Resource newResource(URL url, boolean useCaches) {
    if (url == null) return null;

    String urls = url.toExternalForm();
    if (urls.startsWith("file:")) {
      try {
        FileResource fileResource = new FileResource(url);
        return fileResource;
      } catch (Exception e) {
        Log.debug(Log.EXCEPTION, e);
        return new BadResource(url, e.toString());
      }
    } else if (urls.startsWith("jar:file:")) {
      return new JarFileResource(url, useCaches);
    } else if (urls.startsWith("jar:")) {
      return new JarResource(url, useCaches);
    }

    return new URLResource(url, null, useCaches);
  }
  @Override
  public void bind(InetSocketAddress addr, int backlog) throws IOException {
    if (_started) throw new BindException("Already started");

    // check if there is already a connector listening
    Connector[] connectors = _server.getConnectors();
    if (connectors != null) throw new BindException("Server already bound");

    this._addr = addr;
    if (_executor != null && _server.getThreadPool() == null) {
      if (Log.isDebugEnabled()) Log.debug("using given Executor for server thread pool");
      _server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
    }

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setAcceptors(1);
    connector.setAcceptQueueSize(backlog);
    connector.setPort(addr.getPort());
    connector.setHost(addr.getHostName());
    _server.addConnector(connector);
  }
 /* (non-Javadoc)
  * @see org.mortbay.jetty.client.HttpExchange#onException(java.lang.Throwable)
  */
 protected void onException(Throwable ex) {
   Log.warn("Handshake:" + ex);
   Log.debug(ex);
 }
Ejemplo n.º 9
0
 /* ------------------------------------------------------------ */
 public void setStatsOn(boolean on) {
   if (on && _statsStartedAt != -1) return;
   Log.debug("Statistics on = " + on + " for " + this);
   statsReset();
   _statsStartedAt = on ? System.currentTimeMillis() : -1;
 }
Ejemplo n.º 10
0
 /**
  * Set reverse proxy handling
  *
  * @param check true if this connector is checking the x-forwarded-for/host/server headers
  */
 public void setForwarded(boolean check) {
   if (check) Log.debug(this + " is forwarded");
   _forwarded = check;
 }
Ejemplo n.º 11
0
 public void invalidate() throws IllegalStateException {
   Log.debug("user invalidated session: " + getId());
   _manager.destroySession(this);
 }
Ejemplo n.º 12
0
  /* ------------------------------------------------------------ */
  public static void extract(Resource resource, File directory, boolean deleteOnExit)
      throws IOException {
    if (Log.isDebugEnabled()) Log.debug("Extract " + resource + " to " + directory);

    String urlString = resource.getURL().toExternalForm().trim();
    int endOfJarUrl = urlString.indexOf("!/");
    int startOfJarUrl = (endOfJarUrl >= 0 ? 4 : 0);

    if (endOfJarUrl < 0) throw new IOException("Not a valid jar url: " + urlString);

    URL jarFileURL = new URL(urlString.substring(startOfJarUrl, endOfJarUrl));
    String subEntryName =
        (endOfJarUrl + 2 < urlString.length() ? urlString.substring(endOfJarUrl + 2) : null);
    boolean subEntryIsDir = (subEntryName != null && subEntryName.endsWith("/") ? true : false);

    if (Log.isDebugEnabled())
      Log.debug("Extracting entry = " + subEntryName + " from jar " + jarFileURL);

    InputStream is = jarFileURL.openConnection().getInputStream();
    JarInputStream jin = new JarInputStream(is);
    JarEntry entry = null;
    boolean shouldExtract = true;
    while ((entry = jin.getNextJarEntry()) != null) {
      String entryName = entry.getName();

      if ((subEntryName != null) && (entryName.startsWith(subEntryName))) {
        // if there is a particular subEntry that we are looking for, only
        // extract it.
        if (subEntryIsDir) {
          // if it is a subdirectory we are looking for, then we
          // are looking to extract its contents into the target
          // directory. Remove the name of the subdirectory so
          // that we don't wind up creating it too.
          entryName = entryName.substring(subEntryName.length());
          if (!entryName.equals("")) {
            // the entry is
            shouldExtract = true;
          } else shouldExtract = false;
        } else shouldExtract = true;
      } else if ((subEntryName != null) && (!entryName.startsWith(subEntryName))) {
        // there is a particular entry we are looking for, and this one
        // isn't it
        shouldExtract = false;
      } else {
        // we are extracting everything
        shouldExtract = true;
      }

      if (!shouldExtract) {
        if (Log.isDebugEnabled()) Log.debug("Skipping entry: " + entryName);
        continue;
      }

      File file = new File(directory, entryName);
      if (entry.isDirectory()) {
        // Make directory
        if (!file.exists()) file.mkdirs();
      } else {
        // make directory (some jars don't list dirs)
        File dir = new File(file.getParent());
        if (!dir.exists()) dir.mkdirs();

        // Make file
        FileOutputStream fout = null;
        try {
          fout = new FileOutputStream(file);
          IO.copy(jin, fout);
        } finally {
          IO.close(fout);
        }

        // touch the file.
        if (entry.getTime() >= 0) file.setLastModified(entry.getTime());
      }
      if (deleteOnExit) file.deleteOnExit();
    }
  }