예제 #1
0
  public void close() throws IOException {
    if (m_file != null) {
      m_file.close();
      m_file = null;
    } else if (responseData != null) responseData.close();

    responseData = null;
  }
예제 #2
0
  protected boolean httpServeFile(String strContType) throws IOException {

    String strPath = uri.getPath();
    // if ( !strPath.startsWith("/apps") )
    //	strPath = "/apps" + strPath;

    if (strContType.equals("application/javascript")) {
      responseData = RhoRuby.loadFile(strPath);
      if (responseData == null) {
        String str = "";
        responseData = new ByteArrayInputStream(str.getBytes());
      }
    } else responseData = RhoRuby.loadFile(strPath);

    if (responseData == null) {
      Jsr75File file = new Jsr75File();
      String strFileName = strPath;
      if (strFileName.startsWith("/apps")) strFileName = strPath.substring(5);

      try {
        file.open(strFileName, true, true);
        responseData = file.getInputStream();
        if (responseData != null) {
          contentLength = (int) file.length();
        }
        m_file = file;
      } catch (StorageError exc) {
        file.close();
      } catch (IOException exc) {
        file.close();
      }
    } else {
      if (responseData != null) {
        contentLength = responseData.available();
      }
    }

    if (responseData == null) return false;

    if (strContType.length() > 0) resHeaders.addProperty("Content-Type", strContType);

    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));

    return true;
  }