bool BitmapData::initWithFile(const std::string &path) { _filePath = FileUtils::getInstance()->getFullPath(path); ByteArray *data = FileUtils::getInstance()->getFileData(_filePath, "rb"); bool result = false; if (!data->isNull()) { result = initWithData(data->getBytes(), data->getLength()); } delete data; return result; }
/** * Equality operator * * @param byts const ByteArray& * @return bool */ bool ByteArray::operator== ( const ByteArray& byts) { // Check if the arrays are the same length if ( getLength() != byts.getLength()) return false; // Check if the array is empty if (getLength() == 0) return true; // Check if the array bytes are equal if ( memcmp( getData(), byts.getData(), getLength()) == 0) return true; return false; }
ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, ByteArray buffer) { unsigned char temp_tag[3] = { 0, }; unsigned char temp_tag_len = 0; unsigned char temp_len[5] = { 0, }; unsigned char temp_len_len = 0; ByteArray result; unsigned int total_len = 0; unsigned int current = 0; unsigned char *temp_buffer = NULL; /* add tag's length */ if (tag > 0x7FFF) return result; temp_tag[0] = (tagClass << 6) | (encoding << 5); if (tag < 0x1F) { temp_tag[0] |= tag; temp_tag_len = 1; } else { temp_tag[0] |= 0x1F; if (tag < 0x80) { temp_tag[1] = tag; temp_tag_len = 2; } else { temp_tag[1] = (tag & 0x000000FF); temp_tag[2] = (tag & 0x0000FF00); temp_tag_len = 3; } } total_len += temp_tag_len; /* add length's length */ if (buffer.getLength() < 128) { temp_len[0] = buffer.getLength(); temp_len_len = 1; } else { temp_len[0] = 0x80; temp_len_len = 1; if (buffer.getLength() > 0x00FFFFFF) { temp_len[4] = (buffer.getLength() & 0xFF000000) >> 24; temp_len_len++; } if (buffer.getLength() > 0x0000FFFF) { temp_len[3] = (buffer.getLength() & 0x00FF0000) >> 16; temp_len_len++; }
bool BinaryFile::writeTo(const ByteArray& byteArray) throw() { write(this->fileSignature, byteArray.getBytes(), byteArray.getLength()); return true; }
/** * Copy constructor * * @param byts const ByteArray& */ ByteArray::ByteArray( const ByteArray& byts) { m_data = NULL; m_length = 0; setData( byts.getData(), byts.getLength()); }