Пример #1
0
  public OutputStream openSession(String url, String name) {
    OutputStream oS = null;
    // #if polish.api.fileconnection
    try {
      url += name + ".gpx";
      // #debug info
      logger.info("Opening file " + url);
      session = Connector.open(url);
      FileConnection fileCon = (FileConnection) session;
      if (fileCon == null) throw new IOException("Couldn't open url " + url);
      if (!fileCon.exists()) {
        fileCon.create();
      } else {
        fileCon.truncate(0);
      }

      oS = fileCon.openOutputStream();
    } catch (IOException e) {
      logger.error(
          Locale.get(
                  "fileexportsession.CouldNotObtainConnection") /*Could not obtain connection with */
              + url
              + " ("
              + e.getMessage()
              + ")");
      e.printStackTrace();
    }
    // #endif
    return oS;
  }
Пример #2
0
  /**
   * This method writes to a text file
   *
   * @param fName Name of the file
   * @param text Text to store in the file
   */
  public void writeTextFile(String fName, String text) {
    DataOutputStream os = null;
    FileConnection fconn = null;

    try {

      fconn = (FileConnection) Connector.open("file:///SDCard/BlackBerry/" + fName);
      if (!fconn.exists()) {
        fconn.create();
      } else {
        fconn.truncate(0);
      }
      os = fconn.openDataOutputStream();
      System.out.println(text);
      os.write(text.getBytes());
    } catch (IOException e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        if (null != os) os.close();
        if (null != fconn) fconn.close();
      } catch (IOException e) {
        System.out.println(e.getMessage());
      }
    }
  }
Пример #3
0
 /*     */ public synchronized void saveToDisk() /*     */ {
   /* 106 */ if (this._dirty)
   /*     */ {
     /* 109 */ FileConnection fileC = null;
     /* 110 */ OutputStream os = null;
     /* 111 */ DataOutputStream dOS = null;
     /*     */ try
     /*     */ {
       /* 114 */ String filename = getPath() + "WA_Favorites";
       /* 115 */ Utilities.logData("trying to open favs for write " + filename);
       /* 116 */ fileC = (FileConnection) Connector.open(filename, 3);
       /* 117 */ if (!fileC.exists()) {
         /* 118 */ fileC.create();
         /*     */ }
       /* 120 */ os = fileC.openOutputStream(0L);
       /* 121 */ dOS = new DataOutputStream(os);
       /*     */
       /* 124 */ for (int i = 0; i < this._favoritesList.size(); i++) {
         /* 125 */ String curJid = (String) this._favoritesList.elementAt(i);
         /* 126 */ dOS.writeUTF(curJid);
         /* 127 */ dOS.writeInt(1);
         /*     */ }
       /* 129 */ for (int i = 0; i < this._blackballList.size(); i++) {
         /* 130 */ String curJid = (String) this._blackballList.elementAt(i);
         /* 131 */ dOS.writeUTF(curJid);
         /* 132 */ dOS.writeInt(2);
         /*     */ }
       /* 134 */ dOS.flush();
       /* 135 */ this._dirty = false;
       /*     */ } catch (Throwable x) {
       /* 137 */ Utilities.logData("favorites save blew up with " + t.toString());
       /*     */ } finally {
       /* 139 */ if (dOS != null)
         /*     */ try {
           /* 141 */ dOS.close();
           /*     */ }
         /*     */ catch (Exception x) {
           /*     */ }
       /* 145 */ if (os != null)
         /*     */ try {
           /* 147 */ os.close();
           /*     */ }
         /*     */ catch (Exception x) {
           /*     */ }
       /* 151 */ if (fileC != null)
         /*     */ try {
           /* 153 */ fileC.close();
           /*     */ }
         /*     */ catch (Exception x)
         /*     */ {
           /*     */ }
       /*     */ }
     /*     */ }
   /*     */ }
  public String ReadOutputFile() throws IOException {
    FileConnection fc = null;
    InputStream is = null;
    StringBuffer sb = new StringBuffer();

    try {
      String url = sFileSchema + sFSRoot + sLocalOutputPrefix + "201101" + sOutputExt;
      fc = (FileConnection) Connector.open(url, Connector.READ_WRITE);
      if (fc == null) {
        SetMessages("[!] ERROR: fc == null.");
        System.out.println(GetMessages());
        return null;
      }
      if (!fc.exists()) {
        // SetMessages("[!] ERROR: !fc.exists().");
        // System.out.println(GetMessages());
        fc.create();
        return "";
      }

      is = fc.openInputStream();
      int ch;
      while ((ch = is.read()) != -1) {
        sb.append((char) ch);
      }
    } catch (ConnectionNotFoundException cnfex) {
      SetMessages(cnfex.toString());
      cnfex.printStackTrace();
    } catch (IOException ioex) {
      SetMessages(ioex.toString());
      ioex.printStackTrace();
    } catch (Exception ex) {
      SetMessages(ex.toString());
      ex.printStackTrace();
    } finally {
      if (is != null) {
        is.close();
      }

      if (fc != null) {
        fc.close();
      }
    }

    return sb.toString();
  }
  public boolean WriteLocalFile(String sWriteData, String sFileURL) throws IOException {
    FileConnection fc = null;
    DataOutputStream dos = null;
    // OutputStream os = null;
    // PrintStream ps = null;

    try {
      // If exists already, first delete file, a little clumsy.
      // fc = (FileConnection) Connector.open(fileURL.toString(), Connector.READ_WRITE);
      // String url = sFileSchema + sFSRoot + "expeout_201101" + sFileExt;
      String url = sFileSchema + sFSRoot + sLocalOutputPrefix + "201102" + sOutputExt;
      // fc = (FileConnection) Connector.open(url, Connector.READ_WRITE);
      fc = (FileConnection) Connector.open(sFileURL, Connector.READ_WRITE);
      // fc = (FileConnection) Connector.open(url, Connector.WRITE);
      if (!fc.exists()) {
        fc.create();
      }

      fc.truncate(0);

      dos = new DataOutputStream(fc.openOutputStream());
      // dos.writeUTF(sWriteData);
      // dos.write("ABCDE".getBytes());
      dos.write(sWriteData.getBytes());
      // os = fc.openOutputStream(Long.MAX_VALUE);
      // os = fc.openOutputStream();
      // ps = new PrintStream(os);
      // ps.println(sWriteData);

      SetSuccess(true);
    } catch (ConnectionNotFoundException cnfex) {
      SetSuccess(false);
      SetMessages(cnfex.toString());
      cnfex.printStackTrace();
    } catch (IOException ioex) {
      SetSuccess(false);
      SetMessages(ioex.toString());
      ioex.printStackTrace();
    } catch (Exception ex) {
      SetSuccess(false);
      SetMessages(ex.toString());
      ex.printStackTrace();
    } finally {
      /*if (ps != null) {
          ps.flush();
          ps.close();
      }
      if (os != null) {
          os.flush();
          os.close();
      }*/
      if (dos != null) {
        dos.flush();
        dos.close();
      }
      if (fc != null) {
        fc.close();
      }
    }

    return GetSuccess();
  }
Пример #6
0
  public void filter16to32(short[] inPixels, int[] outPixels) {

    int srcWidth = width;
    int srcHeight = height;
    int srcWidth1 = width - 1;
    int srcHeight1 = height - 1;
    int outWidth = srcWidth;
    int outHeight = srcHeight;
    int outX, outY;
    int index = 0;
    // int[] outTempPixels = new int[outWidth];
    int outpix = 0;
    // enable cache
    if (enablecache) {
      if (cacheStream == null) {
        // if(Runtime.getRuntime().freeMemory()>(mCacheW*mCacheH*8))
        {
          cacheStream = openPreCacheResource(cachefilename);
        }
      }
    }

    // creaet cache
    FileConnection con = null;
    OutputStream os = null;
    if (precache) {
      String filename = System.currentTimeMillis() + "filter" + outWidth + "x" + outHeight + ".wrp";
      try {
        con = (FileConnection) Connector.open(System.getProperty("fileconn.dir.photos") + filename);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (con != null) {
        if (con.exists()) {
          try {
            con.delete();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        try {
          con.create();
          os = con.openOutputStream();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }

    outX = 0;
    outY = 0;
    float[] out = new float[2];
    mProgress = 0;

    for (int y = 0; y < outHeight; y++) {
      for (int x = 0; x < outWidth; x++) {
        if (cacheStream != null) {
          cacheTable((outX + x), (outY + y), out);
        }
        int srcX = (int) Math.floor(out[0]);
        int srcY = (int) Math.floor(out[1]);
        float xWeight = out[0] - srcX;
        float yWeight = out[1] - srcY;
        if (precache) {
          /*
           * try { os.write(float2Byte(out[0]));
           * os.write(float2Byte(out[1])); } catch (IOException e) {
           * // TODO Auto-generated catch block e.printStackTrace(); }
           */
          if (preCacheData == null) {
            int cacheSize = mCacheW * mCacheH * 2;
            preCacheData = new float[cacheSize];
          }
          int c = cacheMaping(x, y);
          preCacheData[c * 2] = out[0];
          preCacheData[c * 2 + 1] = out[1];
        }
        // System.out.println(out[0]+","+out[1]);
        short nw, ne, sw, se;

        if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) {
          // Easy case, all corners are in the image
          int i = srcWidth * srcY + srcX;
          nw = inPixels[i];
          ne = inPixels[i + 1];
          sw = inPixels[i + srcWidth];
          se = inPixels[i + srcWidth + 1];
        } else {
          // Some of the corners are off the image
          nw = getPixel16(inPixels, srcX, srcY, srcWidth, srcHeight);
          ne = getPixel16(inPixels, srcX + 1, srcY, srcWidth, srcHeight);
          sw = getPixel16(inPixels, srcX, srcY + 1, srcWidth, srcHeight);
          se = getPixel16(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight);
        }
        outpix = (outY + y) * width + (outX + x);
        outPixels[outpix] = bilinearInterpolate16to32(xWeight, yWeight, nw, ne, sw, se);
        // outTempPixels[x] = bilinearInterpolate(xWeight,yWeight, nw,
        // ne, sw, se);
      }
      // setRGB( dst, 0, y, transformedSpace.width, 1, outPixels );
      // System.arraycopy(outTempPixels, 0, outPixels, (outY + y) * width,
      // outWidth);
      if (y > 20) mProgress = (int) (((y * 100) / outHeight));
    }

    if (precache) {
      for (int i = 0; i < (mCacheW * mCacheH * 2); i++) {
        try {
          os.write(float2Byte(preCacheData[i]));
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

      try {
        if (os != null) {
          os.close();
        }
        if (con != null) {
          con.close();
        }
      } catch (IOException io) {
      }
    }
  }
  public void run_0420() {
    FileConnection conn1 = null;
    int counter = 0;
    try {
      // Make a connection to the new file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 1;
      System.out.println(" run_0420: counter = 1 ");
      if (conn1.exists()) throw new TestFailedException();
      counter = 2;
      System.out.println(" run_0420: counter = 2 ");
      conn1.create();
      counter = 3;
      System.out.println(" run_0420: counter = 3 ");
      OutputStream stream = conn1.openOutputStream();
      counter = 4;
      System.out.println(" run_0420: counter = 4 ");
      byte[] byteArray1 = new byte[50];
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 55;
      counter = 5;
      System.out.println(" run_0420: counter = 5 ");
      stream.write(byteArray1);
      stream.close();
      counter = 6;
      System.out.println(" run_0420: counter = 6 ");
      // Re-open an OutputStream.
      stream = conn1.openOutputStream(conn1.fileSize());
      counter = 7;
      System.out.println(" run_0420: counter = 7 ");
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 56;
      conn1.close();
      counter = 8;
      stream.write(byteArray1);
      counter = 9;
      stream.close();

      System.out.println(" Going to second part of run_0420");

      // Re-open a connection.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 10;
      System.out.println(" run_0420: counter = 10 ");
      if (!conn1.exists()) throw new TestFailedException();
      counter = 11;
      System.out.println(" run_0420: counter = 11 ");
      InputStream inStream = conn1.openInputStream();
      counter = 12;
      System.out.println(" run_0420: counter = 12 ");
      byte[] byteArray2 = new byte[110];
      int retValue = inStream.read(byteArray2);
      if (retValue != 100) throw new TestFailedException("retValue: " + retValue);
      counter = 13;
      System.out.println(" run_0420: counter = 13 ");
      for (int i = 0; i < retValue; ++i) {
        if (i < 50) {
          if (byteArray2[i] != 55)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        } else if (i > 49) {
          if (byteArray2[i] != 56)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        }
      } // end for
      counter = 14;
      conn1.close();
      inStream.close();

      assertTrue(" run_0420() ok ", true);
    } catch (Exception ex) {
      append(ex.toString());
      append("TEST FAILED!!! Case: run_0420() counter: " + counter + "\n");
      assertTrue(" run_0420() FAILED!!! Counter: " + counter, false);
    }
  } // end run_0420()