// gpg error?
int exitCode = p.waitFor();
if (exitCode != 0)
{
throw new CryptographicException(
"GPG exited abormally. Status code" + exitCode);
}
StringBuffer line = new StringBuffer("");
StringBuffer input = new StringBuffer("");
String gpgMarker = "[GNUPG:]";
while (in.ready())
{
char c = (char)in.read();
line.append(c);
if (c == '\n')
{
String l = line.toString();
if (!l.startsWith(gpgMarker))
{
// GPG Marker is somewhere in
// there, we have to truncate
int pos = l.indexOf(gpgMarker);
if (pos > 0)
{
l = l.substring(0, pos);
}
input.append(l);
}
line = new StringBuffer("");
}
}
// UTF-8 works for ascii amored and
// is default output format for gpg
return input.toString().getBytes("UTF-8");
}
catch (IOException e)
{
throw new CryptographicException(e.getMessage());
}
catch (InterruptedException e)
{
throw new CryptographicException(e.getMessage());
}
}