org.bouncycastle.bcpg.LiteralDataPacket Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpg-lts8on Show documentation
Show all versions of bcpg-lts8on Show documentation
The Bouncy Castle Java APIs for the OpenPGP Protocol. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.
The newest version!
package org.bouncycastle.bcpg;
import java.io.IOException;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Strings;
/**
* Generic literal data packet.
*/
public class LiteralDataPacket
extends InputStreamPacket
{
int format;
byte[] fileName;
long modDate;
LiteralDataPacket(
BCPGInputStream in)
throws IOException
{
this(in, false);
}
LiteralDataPacket(
BCPGInputStream in,
boolean newPacketFormat)
throws IOException
{
super(in, LITERAL_DATA, newPacketFormat);
format = in.read();
int l = in.read();
fileName = new byte[l];
for (int i = 0; i != fileName.length; i++)
{
int ch = in.read();
if (ch < 0)
{
throw new IOException("literal data truncated in header");
}
fileName[i] = (byte)ch;
}
modDate = StreamUtil.readTime(in);
if (modDate < 0)
{
throw new IOException("literal data truncated in header");
}
}
/**
* Return the format tag of the data packet.
*/
public int getFormat()
{
return format;
}
/**
* Return the modification time for the file (milliseconds at second level precision).
*/
public long getModificationTime()
{
return modDate;
}
/**
* Return the file name associated with the data packet.
*/
public String getFileName()
{
return Strings.fromUTF8ByteArray(fileName);
}
/**
* Return the file name as an uninterpreted byte array.
*/
public byte[] getRawFileName()
{
return Arrays.clone(fileName);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy