Package qurtext.domain

Examples of qurtext.domain.Media


  @SuppressWarnings("unchecked")
  private Media getMedia(String urlPath, String params) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      String query = "select from " + Media.class.getName() + " where urlPath=='" + urlPath + "' && filename=='" + params + "'";
      Media result=((Collection<Media>) pm.newQuery(query)
          .execute()).iterator().next();
      return result;
    } catch (NoSuchElementException e){
      return null;
    } finally {
View Full Code Here


  public byte[] getMediaContent(String urlPath, String params, boolean isPost, String cacheKey) {
    if (null!=cacheKey) {
      byte[] content=(byte[]) cache.get(cacheKey);
      if (null!=content) return content;
    }
    Media source=getMedia(urlPath,params);
    if (null!=source) {
      if (null!=cacheKey) {
        byte[] content=source.getContent();
        if (null!=content) cache.put(cacheKey, content);
      }
      return source.getContent();
    }
    HttpURLConnection connection = null;
    try {
      ByteArrayOutputStream result=new ByteArrayOutputStream();
        if (isPost) {
          URL url = new URL(urlPath);
          connection = (HttpURLConnection) url.openConnection();
          connection.setDoOutput(true);
          connection.setRequestMethod("POST");
          OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
        writer.write(params);
          writer.close();
        } else if (params.indexOf("=")<=0) { // not a param but a filename
          URL url = new URL(urlPath + params);
          connection = (HttpURLConnection) url.openConnection();
        } else {
          URL url = new URL(urlPath + "?" + params);
          connection = (HttpURLConnection) url.openConnection();
        }
  
        if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            InputStream reader = connection.getInputStream();
            byte[] buffer=new byte[102400];
            int byteRead;

            while ((byteRead = reader.read(buffer)) > 0) {
                result.write(buffer,0,byteRead);
            }
            reader.close();
            source=new Media(urlPath,params,result.toByteArray());
            saveMedia(source);
        if (null!=cacheKey) {
          byte[] content=source.getContent();
          if (null!=content) cache.put(cacheKey, content);
        }
            return source.getContent();
        } else {
            return connection.getResponseMessage().getBytes();
        }
    } catch (MalformedURLException e) {
        return e.getMessage().getBytes();
View Full Code Here

TOP

Related Classes of qurtext.domain.Media

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.