Ejemplo n.º 1
0
ECode CSoundPool::Load(
    /* [in] */ const String& path,
    /* [in] */ Int32 priority,
    /* [out] */ Int32* result)
{
    VALIDATE_NOT_NULL(result);
    *result = 0;

    if (DEBUG) Logger::D(TAG, "Load priority %d, %s", priority, path.string());

    // pass network streams to player
    if (path.StartWith("http:")) {
        return NativeLoad(path, priority, result);
    }

    // try local path
    ECode ec = NOERROR;
    Boolean fileExists;
    AutoPtr<IParcelFileDescriptor> fd;
    AutoPtr<IFileDescriptor> fileDescriptor;
    Int64 tempValue;

    AutoPtr<IParcelFileDescriptorHelper> parcelFileDescriptorHelper;
    CParcelFileDescriptorHelper::AcquireSingleton((IParcelFileDescriptorHelper**)&parcelFileDescriptorHelper);

    AutoPtr<IFile> f;
    ec = CFile::New(path, (IFile**)&f);
    FAIL_GOTO(ec, _EXIT_);

    f->Exists(&fileExists);
    if (!fileExists) {
        Logger::E(TAG, "error loading %s, file does not exists.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    ec = parcelFileDescriptorHelper->Open(f, IParcelFileDescriptor::MODE_READ_ONLY, (IParcelFileDescriptor**)&fd);
    FAIL_GOTO(ec, _EXIT_);
    if (fd != NULL) {
        ec = fd->GetFileDescriptor((IFileDescriptor**)&fileDescriptor);
        FAIL_GOTO(ec, _EXIT_);

        f->GetLength(&tempValue);
        ec =NativeLoad(fileDescriptor, 0, tempValue, priority, result);
    }

_EXIT_:
    if (fd) {
        fd->Close();
        fd = NULL;
    }

    if (FAILED(ec)) {
        Logger::E(TAG, "error loading %s", path.string());
    }
    return ec;
}
Ejemplo n.º 2
0
ECode PdfEditor::Write(
    /* [in] */ IParcelFileDescriptor* output) /*throws IOException*/
{
    Int32 fd = 0;
    ECode ec = ThrowIfClosed();
    FAIL_GOTO(ec, error);
    ec = NativeWrite(mNativeDocument, (output->GetFd(&fd), fd));
    FAIL_GOTO(ec, error);

error:
    AutoPtr<IIoUtils> iu;
    CIoUtils::AcquireSingleton((IIoUtils**)&iu);
    return iu->CloseQuietly(ICloseable::Probe(output));
}
Ejemplo n.º 3
0
AutoPtr<ArrayOf<Byte> > SystemProperties::GetFakeImage()
{
    // try{
    String filepath("/system/media/PDroid.jpeg");
    AutoPtr<IFile> imagefile;
    AutoPtr<IFileInputStream> fis;
    AutoPtr<IBitmap> bm;
    AutoPtr<IByteArrayOutputStream> helper;
    AutoPtr<ArrayOf<Byte> > bytes;
    Boolean bval;
    AutoPtr<IBitmapFactory> fact;

    FAIL_GOTO(CFile::New(filepath, (IFile**)&imagefile), _EXIT_);
    FAIL_GOTO(CFileInputStream::New(imagefile, (IFileInputStream**)&fis), _EXIT_);

    CBitmapFactory::AcquireSingleton((IBitmapFactory**)&fact);
    FAIL_GOTO(fact->DecodeStream(fis, (IBitmap**)&bm), _EXIT_);

    FAIL_GOTO(CByteArrayOutputStream::New((IByteArrayOutputStream**)&helper), _EXIT_);
    FAIL_GOTO(bm->Compress(BitmapCompressFormat_JPEG, 100 , helper, &bval), _EXIT_);
    FAIL_GOTO(helper->ToByteArray((ArrayOf<Byte>**)&bytes), _EXIT_);

_EXIT_:
    if (fis != NULL) {
        fis->Close();
    }
    return bytes;
    // }
    // catch (Exception e){
    //     Log.e(PRIVACY_TAG,"something went wrong with getting the picture!");
    //     e.printStackTrace();
    //     return NULL;
    // }
}