Permalink
Browse files

Updated, stick with current code style, removed old bytes properties …

…for episodeName and desc, which forces them to be strings and ensures that they can be larger than 32KB and hence app doesn't crash
  • Loading branch information...
Sean Snider
Sean Snider committed Oct 10, 2018
1 parent 213e01c commit 986c0d8ddd93202556b5267d9ca0b1276e145db8
Showing with 9 additions and 67 deletions.
  1. +9 −65 java/sage/Show.java
  2. +0 −2 java/sage/Wizard.java
View
@@ -163,43 +163,11 @@ public String getTitle()
public String getEpisodeName()
{
if (episodeNameBytes != null)
{
// Doing it this way should be thread safe, we may create the String twice but we'd always
// do it from a valid byte array
byte[] testBytes = episodeNameBytes;
if (testBytes != null)
{
try {
episodeNameStr = new String(testBytes, Sage.I18N_CHARSET);
episodeNameBytes = null;
}
catch (UnsupportedEncodingException uee) {
if (Sage.DBG) System.out.println("Unicode ERROR creating String of:" + uee);
}
}
}
return episodeNameStr;
return episodeNameStr;
}
public String getDesc()
{
if (descBytes != null)
{
// Doing it this way should be thread safe, we may create the String twice but we'd always
// do it from a valid byte array
byte[] testBytes = descBytes;
if (testBytes != null)
{
try {
descStr = new String(testBytes, Sage.I18N_CHARSET);
descBytes = null;
}
catch (UnsupportedEncodingException uee) {
if (Sage.DBG) System.out.println("Unicode ERROR creating String of:" + uee);
}
}
}
return descStr;
}
@@ -355,10 +323,8 @@ void update(DBObject x)
lastWatched = fromMe.lastWatched;
dontLike = fromMe.dontLike;
title = fromMe.title;
episodeNameBytes = fromMe.episodeNameBytes;
episodeNameStr = fromMe.episodeNameStr;
externalID = fromMe.externalID;
descBytes = fromMe.descBytes;
descStr = fromMe.descStr;
categories = fromMe.categories;
people = fromMe.people;
@@ -461,20 +427,10 @@ public boolean isIdentical(Show other)
title = wiz.getTitleForID(readID(in, idMap));
// We lazily create these String to speed up loading time and reduce memory overhead
int size = in.readShort();
if (size == 0)
episodeNameStr = "";
else {
episodeNameBytes = new byte[size];
in.readFully(episodeNameBytes);
}
size = in.readShort();
if (size == 0)
descStr = "";
else {
descBytes = new byte[size];
in.readFully(descBytes);
}
int size = 0;
episodeNameStr = in.readUTF();
descStr = in.readUTF();
Stringer category = wiz.getCategoryForID(readID(in, idMap));
Stringer subCategory = wiz.getSubCategoryForID(readID(in, idMap));
@@ -649,20 +605,10 @@ void write(DataOutput out, int flags) throws IOException
boolean useLookupIdx = (flags & Wizard.WRITE_OPT_USE_ARRAY_INDICES) != 0;
out.writeLong(duration);
out.writeInt((title == null) ? 0 : (useLookupIdx ? title.lookupIdx : title.id));
byte[] barr = episodeNameBytes;
if (barr != null) {
out.writeShort(barr.length);
out.write(barr);
}
else
out.writeUTF(episodeNameStr);
barr = descBytes;
if (barr != null) {
out.writeShort(barr.length);
out.write(barr);
}
else
out.writeUTF(descStr);
out.writeUTF(episodeNameStr);
out.writeUTF(descStr);
out.writeInt((categories.length == 0) ? 0 : (useLookupIdx ? categories[0].lookupIdx : categories[0].id));
out.writeInt((categories.length < 2) ? 0 : (useLookupIdx ? categories[1].lookupIdx : categories[1].id));
@@ -1536,9 +1482,7 @@ public static String getImageIdUrl(int packedImageId, int rootId, int altFilmId,
long duration;
Stringer title;
volatile String episodeNameStr;
byte[] episodeNameBytes;
volatile String descStr;
byte[] descBytes;
Stringer[] categories;
Person[] people;
byte[] roles;
View
@@ -4541,9 +4541,7 @@ private Show addShow(String title, String episodeName, String desc, long duratio
s.duration = duration;
s.title = getTitleForName(title, mediaMask);
s.episodeNameStr = (episodeName == null) ? "" : new String(episodeName);
s.episodeNameBytes = null;
s.descStr = (desc == null) ? "" : new String(desc);
s.descBytes = null;
if (!fromAPlugin && extID.startsWith("MV") && (categories == null || categories.length == 0 || !Sage.rez("Movie").equals(categories[0])))
{
if (categories == null)

0 comments on commit 986c0d8

Please sign in to comment.