public static Car instantiateCar(String object) {
    if (object == null) return null;

    ObjectInputStream ois = null;
    try {
      Base64InputStream b64 =
          new Base64InputStream(new ByteArrayInputStream(object.getBytes()), Base64.DEFAULT);
      ois = new ObjectInputStream(b64);
      Car car = (Car) ois.readObject();
      return car;
    } catch (StreamCorruptedException e) {
      logger.warn(e.getMessage(), e);
    } catch (IOException e) {
      logger.warn(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      logger.warn(e.getMessage(), e);
    } finally {
      if (ois != null)
        try {
          ois.close();
        } catch (IOException e) {
          logger.warn(e.getMessage(), e);
        }
    }
    return null;
  }
Esempio n. 2
0
 public short[] decode_frame(byte[] bytes) {
   try {
     _spxd.processData(bytes, 0, bytes.length);
   } catch (StreamCorruptedException ex) {
     Log.error("Speex Decoder error " + ex.getMessage());
   }
   short audioOut[] = new short[_aframesz];
   int decsize = _spxd.getProcessedData(audioOut, 0);
   return audioOut;
 }
Esempio n. 3
0
  /**
   * @param path
   * @return byte or null
   */
  public byte[] getFile(String path) {
    Log.d(TAG, "get file " + path); // NON-NLS

    File f = new File(getFullCachePath(path));
    if (!f.exists()) {
      Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS
      return null;
    }

    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      FileInputStream fileInputStream = new FileInputStream(f);
      byte[] buf = new byte[1024];
      int numRead = 0;
      while ((numRead = fileInputStream.read(buf)) != -1) out.write(buf, 0, numRead);

      fileInputStream.close();

      return out.toByteArray();

    } catch (FileNotFoundException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (StreamCorruptedException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IOException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IllegalArgumentException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (RuntimeException e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (Exception e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    }
  }
 /** This method loads the fingerprint template if it exists. */
 private void loadEnrolledTemplateIfExists() {
   File enrolledFile = getFileStreamPath(ENROLL_FILENAME);
   if (enrolledFile.exists()) {
     try {
       FileInputStream enrollStream = openFileInput(ENROLL_FILENAME);
       ObjectInputStream ois = new ObjectInputStream(enrollStream);
       mEnrolledTemplate = (FingerprintTemplate) ois.readObject();
     } catch (FileNotFoundException e) {
       Log.e(TAG, e.getMessage());
     } catch (StreamCorruptedException e) {
       Log.e(TAG, e.getMessage());
     } catch (IOException e) {
       Log.e(TAG, e.getMessage());
     } catch (ClassNotFoundException e) {
       Log.e(TAG, e.getMessage());
     }
   }
 }
Esempio n. 5
0
  /**
   * @param path
   * @param t
   * @return
   */
  public List<?> getList(String path, java.lang.reflect.Type t) {
    Log.d(TAG, "get list " + path); // NON-NLS

    File f = new File(getFullCachePath(path));
    if (!f.exists()) {
      Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS
      return null;
    }

    List<?> list;
    try {
      StringBuffer fileData = new StringBuffer();
      BufferedReader reader = new BufferedReader(new FileReader(f));
      char[] buf = new char[1024];
      int numRead = 0;
      while ((numRead = reader.read(buf)) != -1) {
        String readData = String.valueOf(buf, 0, numRead);
        fileData.append(readData);
      }
      reader.close();
      String json = fileData.toString();
      Log.d(TAG, "cache: " + json); // NON-NLS

      list = gson.fromJson(json, t);
    } catch (FileNotFoundException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (StreamCorruptedException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IOException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (JsonSyntaxException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IllegalArgumentException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (RuntimeException e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (Exception e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    }

    return list;
  }
Esempio n. 6
0
  public <T> T get(String path, Class<T> c) {
    Log.d(TAG, "get " + path); // NON-NLS

    File f = new File(getFullCachePath(path));
    if (!f.exists()) {
      Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS
      return null;
    }

    T object;
    try {
      StringBuffer fileData = new StringBuffer();
      BufferedReader reader = new BufferedReader(new FileReader(f));
      char[] buf = new char[1024];
      int numRead = 0;
      while ((numRead = reader.read(buf)) != -1) {
        String readData = String.valueOf(buf, 0, numRead);
        fileData.append(readData);
      }
      reader.close();
      String json = fileData.toString();
      Log.d(TAG, "cache: " + json); // NON-NLS

      object = getGson().fromJson(json, c);
    } catch (FileNotFoundException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (StreamCorruptedException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IOException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (JsonSyntaxException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (IllegalArgumentException e) {
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (RuntimeException e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    } catch (Exception e) {
      // не позволим кэшу убить нашу программу
      Log.w(TAG, e.getMessage());
      e.printStackTrace();
      absoluteDelete(path);
      return null;
    }

    if (object.getClass().toString().equals(c.toString())) return object;
    else return null;
  }