public static String getSize(AttachmentProxy a, ReadableDatabase database) {
    if (a.getFile() != null) {
      int size = (int) a.getFile().length();
      return getSizeInKb(size);
    }

    AttachmentPacket packet = a.getPendingPacket();
    if (packet != null) {
      return getSizeInKb(packet.getFileSize());
    }

    int size = 0;
    UniversalId id = a.getUniversalId();
    try {
      DatabaseKey key = DatabaseKey.createMutableKey(id);
      if (!database.doesRecordExist(key)) key = DatabaseKey.createImmutableKey(id);
      if (!database.doesRecordExist(key)) return "";
      size = database.getRecordSize(key);
    } catch (Exception e) {
      e.printStackTrace();
    }

    size -= 1024; // Public code & overhead
    size = size * 3 / 4; // Base64 overhead
    return getSizeInKb(size);
  }
  protected void setUp() throws Exception {
    super.setUp();
    logger = new LoggerToNull();
    MockMartusSecurity serverSecurity = MockMartusSecurity.createServer();
    coreServer = new MockMartusServer(this);
    coreServer.setSecurity(serverSecurity);
    server = new ServerForMirroring(coreServer, logger);

    clientSecurity1 = MockMartusSecurity.createClient();
    clientSecurity2 = MockMartusSecurity.createOtherClient();

    Database db = coreServer.getWriteableDatabase();

    bhp1 = new BulletinHeaderPacket(clientSecurity1);
    bhp1.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key1 = bhp1.createKeyWithHeaderStatus(bhp1.getUniversalId());
    bhp1.writeXmlToDatabase(db, key1, false, clientSecurity1);

    bhp2 = new BulletinHeaderPacket(clientSecurity1);
    bhp2.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key2 = bhp2.createKeyWithHeaderStatus(bhp2.getUniversalId());
    bhp2.writeXmlToDatabase(db, key2, false, clientSecurity1);

    bhp3 = new BulletinHeaderPacket(clientSecurity2);
    bhp3.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key3 = bhp3.createKeyWithHeaderStatus(bhp3.getUniversalId());
    bhp3.writeXmlToDatabase(db, key3, false, clientSecurity2);

    bhp4 = new BulletinHeaderPacket(clientSecurity2);
    bhp4.setStatus(BulletinConstants.STATUSMUTABLE);
    DatabaseKey key4 = bhp4.createKeyWithHeaderStatus(bhp4.getUniversalId());
    bhp4.writeXmlToDatabase(db, key4, false, clientSecurity2);

    UniversalId fdpUid = FieldDataPacket.createUniversalId(clientSecurity1);
    FieldSpec[] tags = {LegacyCustomFields.createFromLegacy("whatever")};
    FieldDataPacket fdp1 = new FieldDataPacket(fdpUid, new FieldSpecCollection(tags));
    fdp1.writeXmlToClientDatabase(db, false, clientSecurity1);

    UniversalId otherPacketId =
        UniversalIdForTesting.createFromAccountAndPrefix(clientSecurity2.getPublicKeyString(), "X");
    DatabaseKey key = DatabaseKey.createImmutableKey(otherPacketId);
    db.writeRecord(key, "Not a valid packet");
  }