mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 02:15:31 +02:00
[releng][cleanup] Fix @since tags according to API Tooling
This commit is contained in:
parent
8370ee1662
commit
ea0adaea28
3 changed files with 129 additions and 126 deletions
|
@ -7,10 +7,10 @@
|
||||||
*
|
*
|
||||||
* Initial Contributors:
|
* Initial Contributors:
|
||||||
* The following IBM employees contributed to the Remote System Explorer
|
* The following IBM employees contributed to the Remote System Explorer
|
||||||
* component that contains this file: David McKnight, Kushal Munir,
|
* component that contains this file: David McKnight, Kushal Munir,
|
||||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||||
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
||||||
|
@ -27,12 +27,13 @@ import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a tar file entry.
|
* This class represents a tar file entry.
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class TarEntry implements Cloneable {
|
public class TarEntry implements Cloneable {
|
||||||
|
|
||||||
// NOTE: Read the GNU tar specification to understand what each of the fields mean.
|
// NOTE: Read the GNU tar specification to understand what each of the fields mean.
|
||||||
// http://www.gnu.org/software/tar/manual/html_mono/tar.html#SEC118
|
// http://www.gnu.org/software/tar/manual/html_mono/tar.html#SEC118
|
||||||
|
|
||||||
// TODO (KM): Do we need to worry about ASCII? I think we do. We are constantly
|
// TODO (KM): Do we need to worry about ASCII? I think we do. We are constantly
|
||||||
// switching between bytes and String assuming local encoding. However, the tar specification states
|
// switching between bytes and String assuming local encoding. However, the tar specification states
|
||||||
// local ASCII variant must always be used. I think our code will probably fail on non-ASCII machines
|
// local ASCII variant must always be used. I think our code will probably fail on non-ASCII machines
|
||||||
|
@ -41,7 +42,7 @@ public class TarEntry implements Cloneable {
|
||||||
// local variant of ASCII? Can we just use US-ASCII everywhere and get away with it. I think
|
// local variant of ASCII? Can we just use US-ASCII everywhere and get away with it. I think
|
||||||
// that should work. Local variant of ASCII possibly means slightly different versions of ASCII used
|
// that should work. Local variant of ASCII possibly means slightly different versions of ASCII used
|
||||||
// on different machines, but not between locales.
|
// on different machines, but not between locales.
|
||||||
|
|
||||||
// block header fields
|
// block header fields
|
||||||
public byte[] name = new byte[ITarConstants.NAME_LENGTH];
|
public byte[] name = new byte[ITarConstants.NAME_LENGTH];
|
||||||
public byte[] mode = new byte[ITarConstants.MODE_LENGTH];
|
public byte[] mode = new byte[ITarConstants.MODE_LENGTH];
|
||||||
|
@ -70,7 +71,7 @@ public class TarEntry implements Cloneable {
|
||||||
public TarEntry(String name) {
|
public TarEntry(String name) {
|
||||||
setName(name);
|
setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new tar entry from the given block data. Fills in all the fields from the
|
* Creates a new tar entry from the given block data. Fills in all the fields from the
|
||||||
* block data.
|
* block data.
|
||||||
|
@ -81,26 +82,26 @@ public class TarEntry implements Cloneable {
|
||||||
*/
|
*/
|
||||||
TarEntry(byte[] blockData) throws IOException {
|
TarEntry(byte[] blockData) throws IOException {
|
||||||
checkNull(blockData);
|
checkNull(blockData);
|
||||||
|
|
||||||
if (blockData.length != ITarConstants.BLOCK_SIZE) {
|
if (blockData.length != ITarConstants.BLOCK_SIZE) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
populateFields(blockData);
|
populateFields(blockData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills in the fields of the entry from block data.
|
* Fills in the fields of the entry from block data.
|
||||||
* @param blockData data in a header block.
|
* @param blockData data in a header block.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private void populateFields(byte[] blockData) throws IOException {
|
private void populateFields(byte[] blockData) throws IOException {
|
||||||
|
|
||||||
InputStream byteStream = new ByteArrayInputStream(blockData);
|
InputStream byteStream = new ByteArrayInputStream(blockData);
|
||||||
|
|
||||||
// read the name
|
// read the name
|
||||||
byteStream.read(name);
|
byteStream.read(name);
|
||||||
|
|
||||||
// if the name is an empty string, then don't fill in other fields,
|
// if the name is an empty string, then don't fill in other fields,
|
||||||
// since this indicates that we have reached end of file
|
// since this indicates that we have reached end of file
|
||||||
if (getName().equals("")) { //$NON-NLS-1$
|
if (getName().equals("")) { //$NON-NLS-1$
|
||||||
|
@ -123,7 +124,7 @@ public class TarEntry implements Cloneable {
|
||||||
byteStream.read(devminor);
|
byteStream.read(devminor);
|
||||||
byteStream.read(prefix);
|
byteStream.read(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given object is null, and throws a <code>NullPointerException</code> if the
|
* Checks whether the given object is null, and throws a <code>NullPointerException</code> if the
|
||||||
* obect is <code>null</code>.
|
* obect is <code>null</code>.
|
||||||
|
@ -131,12 +132,12 @@ public class TarEntry implements Cloneable {
|
||||||
* @throws NullPointerException if the given object is <code>null</code>.
|
* @throws NullPointerException if the given object is <code>null</code>.
|
||||||
*/
|
*/
|
||||||
private void checkNull(Object o) {
|
private void checkNull(Object o) {
|
||||||
|
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of the tar entry.
|
* Sets the name of the tar entry.
|
||||||
* @param fileName the name for the tar entry.
|
* @param fileName the name for the tar entry.
|
||||||
|
@ -144,17 +145,17 @@ public class TarEntry implements Cloneable {
|
||||||
*/
|
*/
|
||||||
public void setName(String fileName) {
|
public void setName(String fileName) {
|
||||||
checkNull(fileName);
|
checkNull(fileName);
|
||||||
|
|
||||||
int length = ITarConstants.NAME_LENGTH - fileName.length();
|
int length = ITarConstants.NAME_LENGTH - fileName.length();
|
||||||
|
|
||||||
// append null characters to the name
|
// append null characters to the name
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
fileName = fileName + "\0"; //$NON-NLS-1$
|
fileName = fileName + "\0"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
name = fileName.getBytes();
|
name = fileName.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name.
|
* Gets the name.
|
||||||
* @return the name.
|
* @return the name.
|
||||||
|
@ -162,7 +163,7 @@ public class TarEntry implements Cloneable {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return (new String(name)).trim();
|
return (new String(name)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the user mod.
|
* Sets the user mod.
|
||||||
* @param canRead <code>true</code> if the user has read permission, <code>false</code> otherwise.
|
* @param canRead <code>true</code> if the user has read permission, <code>false</code> otherwise.
|
||||||
|
@ -170,27 +171,27 @@ public class TarEntry implements Cloneable {
|
||||||
* @param canExecute <code>true</code> if the user has execute permission, <code>false</code> otherwise.
|
* @param canExecute <code>true</code> if the user has execute permission, <code>false</code> otherwise.
|
||||||
*/
|
*/
|
||||||
public void setUserMode(boolean canRead, boolean canWrite, boolean canExecute) {
|
public void setUserMode(boolean canRead, boolean canWrite, boolean canExecute) {
|
||||||
|
|
||||||
int mod = 00;
|
int mod = 00;
|
||||||
|
|
||||||
if (canRead) {
|
if (canRead) {
|
||||||
mod += 04;
|
mod += 04;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canWrite) {
|
if (canWrite) {
|
||||||
mod += 02;
|
mod += 02;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canExecute) {
|
if (canExecute) {
|
||||||
mod += 01;
|
mod += 01;
|
||||||
}
|
}
|
||||||
|
|
||||||
String modString = "0100" + Integer.toString(mod, 8) + "44"; //$NON-NLS-1$ //$NON-NLS-2$
|
String modString = "0100" + Integer.toString(mod, 8) + "44"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
modString = modString + "\0"; //$NON-NLS-1$
|
modString = modString + "\0"; //$NON-NLS-1$
|
||||||
|
|
||||||
mode = modString.getBytes();
|
mode = modString.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the mode in octal.
|
* Gets the mode in octal.
|
||||||
* @return the mode.
|
* @return the mode.
|
||||||
|
@ -198,7 +199,7 @@ public class TarEntry implements Cloneable {
|
||||||
public String getMode() {
|
public String getMode() {
|
||||||
return (new String(mode)).trim();
|
return (new String(mode)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the uid in octal.
|
* Gets the uid in octal.
|
||||||
* @return the uid.
|
* @return the uid.
|
||||||
|
@ -206,7 +207,7 @@ public class TarEntry implements Cloneable {
|
||||||
public String getUID() {
|
public String getUID() {
|
||||||
return (new String(uid)).trim();
|
return (new String(uid)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the gid in octal.
|
* Gets the gid in octal.
|
||||||
* @return the gid.
|
* @return the gid.
|
||||||
|
@ -214,32 +215,32 @@ public class TarEntry implements Cloneable {
|
||||||
public String getGID() {
|
public String getGID() {
|
||||||
return (new String(gid)).trim();
|
return (new String(gid)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the file size in bytes.
|
* Sets the file size in bytes.
|
||||||
* @param fileSize the file size.
|
* @param fileSize the file size.
|
||||||
*/
|
*/
|
||||||
public void setSize(long fileSize) {
|
public void setSize(long fileSize) {
|
||||||
|
|
||||||
// get the octal representation of the file size as a string
|
// get the octal representation of the file size as a string
|
||||||
String sizeString = Long.toString(fileSize, 8).trim();
|
String sizeString = Long.toString(fileSize, 8).trim();
|
||||||
|
|
||||||
// get the length of the string
|
// get the length of the string
|
||||||
int length = sizeString.length();
|
int length = sizeString.length();
|
||||||
|
|
||||||
int diff = ITarConstants.SIZE_LENGTH - length - 1;
|
int diff = ITarConstants.SIZE_LENGTH - length - 1;
|
||||||
|
|
||||||
// prepend the string with 0s
|
// prepend the string with 0s
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
sizeString = "0" + sizeString; //$NON-NLS-1$
|
sizeString = "0" + sizeString; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a space at the end
|
// append a space at the end
|
||||||
sizeString = sizeString + " "; //$NON-NLS-1$
|
sizeString = sizeString + " "; //$NON-NLS-1$
|
||||||
|
|
||||||
size = sizeString.getBytes();
|
size = sizeString.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the size in bytes.
|
* Gets the size in bytes.
|
||||||
* @return the size.
|
* @return the size.
|
||||||
|
@ -247,32 +248,32 @@ public class TarEntry implements Cloneable {
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return Long.parseLong((new String(size)).trim(), 8);
|
return Long.parseLong((new String(size)).trim(), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the modification time.
|
* Sets the modification time.
|
||||||
* @param modTime the modification time, in milliseconds since 00:00:00 GMT, January 1, 1970.
|
* @param modTime the modification time, in milliseconds since 00:00:00 GMT, January 1, 1970.
|
||||||
*/
|
*/
|
||||||
public void setModificationTime(long modTime) {
|
public void setModificationTime(long modTime) {
|
||||||
|
|
||||||
// get the octal representation of the modification time as a string
|
// get the octal representation of the modification time as a string
|
||||||
String mtimeString = Long.toString(modTime/1000, 8).trim();
|
String mtimeString = Long.toString(modTime/1000, 8).trim();
|
||||||
|
|
||||||
// get the length of the string
|
// get the length of the string
|
||||||
int length = mtimeString.length();
|
int length = mtimeString.length();
|
||||||
|
|
||||||
int diff = ITarConstants.MTIME_LENGTH - length - 1;
|
int diff = ITarConstants.MTIME_LENGTH - length - 1;
|
||||||
|
|
||||||
// prepend the string with 0s
|
// prepend the string with 0s
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
mtimeString = "0" + mtimeString; //$NON-NLS-1$
|
mtimeString = "0" + mtimeString; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a space at the end
|
// append a space at the end
|
||||||
mtimeString = mtimeString + " "; //$NON-NLS-1$
|
mtimeString = mtimeString + " "; //$NON-NLS-1$
|
||||||
|
|
||||||
mtime = mtimeString.getBytes();
|
mtime = mtimeString.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the modification time, in milliseconds since 00:00:00 GMT, January 1, 1970.
|
* Gets the modification time, in milliseconds since 00:00:00 GMT, January 1, 1970.
|
||||||
* @return the modification time.
|
* @return the modification time.
|
||||||
|
@ -280,7 +281,7 @@ public class TarEntry implements Cloneable {
|
||||||
public long getModificationTime() {
|
public long getModificationTime() {
|
||||||
return Long.parseLong((new String(mtime)).trim(), 8) * 1000;
|
return Long.parseLong((new String(mtime)).trim(), 8) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the checksum.
|
* Gets the checksum.
|
||||||
* @return the checksum.
|
* @return the checksum.
|
||||||
|
@ -307,13 +308,13 @@ public class TarEntry implements Cloneable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the archive was output in the P1003 archive format.
|
* Returns whether the archive was output in the P1003 archive format.
|
||||||
* This is not used.
|
* This is not used.
|
||||||
* @return the magic field.
|
* @return the magic field.
|
||||||
*/
|
*/
|
||||||
public String getMagic() {
|
public String getMagic() {
|
||||||
return (new String(magic)).trim();
|
return (new String(magic)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version in octal.
|
* Gets the version in octal.
|
||||||
* @return the version.
|
* @return the version.
|
||||||
|
@ -321,7 +322,7 @@ public class TarEntry implements Cloneable {
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return (new String(version)).trim();
|
return (new String(version)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the user name of the tar entry.
|
* Sets the user name of the tar entry.
|
||||||
* @param userName the user name for the tar entry.
|
* @param userName the user name for the tar entry.
|
||||||
|
@ -329,14 +330,14 @@ public class TarEntry implements Cloneable {
|
||||||
*/
|
*/
|
||||||
public void setUserName(String userName) {
|
public void setUserName(String userName) {
|
||||||
checkNull(userName);
|
checkNull(userName);
|
||||||
|
|
||||||
int length = ITarConstants.UNAME_LENGTH - userName.length();
|
int length = ITarConstants.UNAME_LENGTH - userName.length();
|
||||||
|
|
||||||
// append null characters to the user name
|
// append null characters to the user name
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
userName = userName + "\0"; //$NON-NLS-1$
|
userName = userName + "\0"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
uname = userName.getBytes();
|
uname = userName.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +372,7 @@ public class TarEntry implements Cloneable {
|
||||||
public String getDevMinor() {
|
public String getDevMinor() {
|
||||||
return (new String(devminor)).trim();
|
return (new String(devminor)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the prefix in octal.
|
* Gets the prefix in octal.
|
||||||
* @return the prefix.
|
* @return the prefix.
|
||||||
|
@ -379,15 +380,15 @@ public class TarEntry implements Cloneable {
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return (new String(prefix)).trim();
|
return (new String(prefix)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the entry represents a directory.
|
* Returns whether the entry represents a directory.
|
||||||
* @return <code>true</code> if the entry represents a directory, <code>false</code> otherwise.
|
* @return <code>true</code> if the entry represents a directory, <code>false</code> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
|
|
||||||
String entryName = getName();
|
String entryName = getName();
|
||||||
|
|
||||||
if (entryName.endsWith("/")) { //$NON-NLS-1$
|
if (entryName.endsWith("/")) { //$NON-NLS-1$
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -395,7 +396,7 @@ public class TarEntry implements Cloneable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the fields to the given output stream.
|
* Write the fields to the given output stream.
|
||||||
* @param outStream the output stream to write to.
|
* @param outStream the output stream to write to.
|
||||||
|
@ -418,113 +419,113 @@ public class TarEntry implements Cloneable {
|
||||||
outStream.write(devminor);
|
outStream.write(devminor);
|
||||||
outStream.write(prefix);
|
outStream.write(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the checksum of the entry.
|
* Calculates the checksum of the entry.
|
||||||
*/
|
*/
|
||||||
public void calculateChecksum() {
|
public void calculateChecksum() {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
// add name bytes
|
// add name bytes
|
||||||
for (int i = 0; i < name.length; i++) {
|
for (int i = 0; i < name.length; i++) {
|
||||||
sum += name[i];
|
sum += name[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add mode bytes
|
// add mode bytes
|
||||||
for (int i = 0; i < mode.length; i++) {
|
for (int i = 0; i < mode.length; i++) {
|
||||||
sum += mode[i];
|
sum += mode[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add uid bytes
|
// add uid bytes
|
||||||
for (int i = 0; i < uid.length; i++) {
|
for (int i = 0; i < uid.length; i++) {
|
||||||
sum += uid[i];
|
sum += uid[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add gid bytes
|
// add gid bytes
|
||||||
for (int i = 0; i < gid.length; i++) {
|
for (int i = 0; i < gid.length; i++) {
|
||||||
sum += gid[i];
|
sum += gid[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add size bytes
|
// add size bytes
|
||||||
for (int i = 0; i < size.length; i++) {
|
for (int i = 0; i < size.length; i++) {
|
||||||
sum += size[i];
|
sum += size[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add mtime bytes
|
// add mtime bytes
|
||||||
for (int i = 0; i < mtime.length; i++) {
|
for (int i = 0; i < mtime.length; i++) {
|
||||||
sum += mtime[i];
|
sum += mtime[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add checksum bytes assuming check sum is blank spaces
|
// add checksum bytes assuming check sum is blank spaces
|
||||||
char space = ' ';
|
char space = ' ';
|
||||||
byte spaceByte = (byte)space;
|
byte spaceByte = (byte)space;
|
||||||
|
|
||||||
for (int i = 0; i < chksum.length; i++) {
|
for (int i = 0; i < chksum.length; i++) {
|
||||||
sum += spaceByte;
|
sum += spaceByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add typeflag byte
|
// add typeflag byte
|
||||||
sum += typeflag;
|
sum += typeflag;
|
||||||
|
|
||||||
// add linkname bytes
|
// add linkname bytes
|
||||||
for (int i = 0; i < linkname.length; i++) {
|
for (int i = 0; i < linkname.length; i++) {
|
||||||
sum += linkname[i];
|
sum += linkname[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add magic bytes
|
// add magic bytes
|
||||||
for (int i = 0; i < magic.length; i++) {
|
for (int i = 0; i < magic.length; i++) {
|
||||||
sum += magic[i];
|
sum += magic[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add version bytes
|
// add version bytes
|
||||||
for (int i = 0; i < version.length; i++) {
|
for (int i = 0; i < version.length; i++) {
|
||||||
sum += version[i];
|
sum += version[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add uname bytes
|
// add uname bytes
|
||||||
for (int i = 0; i < uname.length; i++) {
|
for (int i = 0; i < uname.length; i++) {
|
||||||
sum += uname[i];
|
sum += uname[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add gname bytes
|
// add gname bytes
|
||||||
for (int i = 0; i < gname.length; i++) {
|
for (int i = 0; i < gname.length; i++) {
|
||||||
sum += gname[i];
|
sum += gname[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add devmajor bytes
|
// add devmajor bytes
|
||||||
for (int i = 0; i < devmajor.length; i++) {
|
for (int i = 0; i < devmajor.length; i++) {
|
||||||
sum += devmajor[i];
|
sum += devmajor[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add devminor bytes
|
// add devminor bytes
|
||||||
for (int i = 0; i < devminor.length; i++) {
|
for (int i = 0; i < devminor.length; i++) {
|
||||||
sum += devminor[i];
|
sum += devminor[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add prefix bytes
|
// add prefix bytes
|
||||||
for (int i = 0; i < prefix.length; i++) {
|
for (int i = 0; i < prefix.length; i++) {
|
||||||
sum += prefix[i];
|
sum += prefix[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the octal representation of the sum as a string
|
// get the octal representation of the sum as a string
|
||||||
String sumString = Long.toString(sum, 8).trim();
|
String sumString = Long.toString(sum, 8).trim();
|
||||||
|
|
||||||
// get the length of the string
|
// get the length of the string
|
||||||
int length = sumString.length();
|
int length = sumString.length();
|
||||||
|
|
||||||
int diff = ITarConstants.CHKSUM_LENGTH - length - 2;
|
int diff = ITarConstants.CHKSUM_LENGTH - length - 2;
|
||||||
|
|
||||||
// prepend the string with 0s
|
// prepend the string with 0s
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
sumString = "0" + sumString; //$NON-NLS-1$
|
sumString = "0" + sumString; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a null character
|
// append a null character
|
||||||
sumString = sumString + "\0"; //$NON-NLS-1$
|
sumString = sumString + "\0"; //$NON-NLS-1$
|
||||||
|
|
||||||
// append a space
|
// append a space
|
||||||
sumString = sumString + " "; //$NON-NLS-1$
|
sumString = sumString + " "; //$NON-NLS-1$
|
||||||
|
|
||||||
// set the checksum
|
// set the checksum
|
||||||
chksum = sumString.getBytes();
|
chksum = sumString.getBytes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
*
|
*
|
||||||
* Initial Contributors:
|
* Initial Contributors:
|
||||||
* The following IBM employees contributed to the Remote System Explorer
|
* The following IBM employees contributed to the Remote System Explorer
|
||||||
* component that contains this file: David McKnight, Kushal Munir,
|
* component that contains this file: David McKnight, Kushal Munir,
|
||||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
||||||
* Johnson Ma (Wind River) - [195402] Add tar.gz archive support
|
* Johnson Ma (Wind River) - [195402] Add tar.gz archive support
|
||||||
|
@ -30,18 +30,19 @@ import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to read entries from a tar file.
|
* This class is used to read entries from a tar file.
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class TarFile {
|
public class TarFile {
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
private Vector blockHeaders;
|
private Vector blockHeaders;
|
||||||
|
|
||||||
private class TarEntryInputStream extends InputStream {
|
private class TarEntryInputStream extends InputStream {
|
||||||
|
|
||||||
private long size;
|
private long size;
|
||||||
private InputStream stream;
|
private InputStream stream;
|
||||||
private long numRead;
|
private long numRead;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a tar entry input stream.
|
* Creates a tar entry input stream.
|
||||||
* @param size the size of the data in the tar entry.
|
* @param size the size of the data in the tar entry.
|
||||||
|
@ -52,12 +53,12 @@ public class TarFile {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
numRead = 0;
|
numRead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see java.io.InputStream#read()
|
* @see java.io.InputStream#read()
|
||||||
*/
|
*/
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
|
|
||||||
if (numRead >= size) {
|
if (numRead >= size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -66,18 +67,18 @@ public class TarFile {
|
||||||
return stream.read();
|
return stream.read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see java.io.InputStream#available()
|
* @see java.io.InputStream#available()
|
||||||
*/
|
*/
|
||||||
public int available() throws IOException {
|
public int available() throws IOException {
|
||||||
|
|
||||||
// get difference between file size and how much we have already read
|
// get difference between file size and how much we have already read
|
||||||
long diff = size - numRead;
|
long diff = size - numRead;
|
||||||
|
|
||||||
// get how much we can read from underlying stream.
|
// get how much we can read from underlying stream.
|
||||||
int av = stream.available();
|
int av = stream.available();
|
||||||
|
|
||||||
// return the smaller of the two
|
// return the smaller of the two
|
||||||
// note although diff is a long, if it's smaller than av, we know it must fit
|
// note although diff is a long, if it's smaller than av, we know it must fit
|
||||||
// in an integer.
|
// in an integer.
|
||||||
|
@ -124,7 +125,7 @@ public class TarFile {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
loadTarEntries();
|
loadTarEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a tar file for reading given the file name.
|
* Opens a tar file for reading given the file name.
|
||||||
* @param name the name of the tar file to be opened for reading.
|
* @param name the name of the tar file to be opened for reading.
|
||||||
|
@ -134,7 +135,7 @@ public class TarFile {
|
||||||
public TarFile(String name) throws FileNotFoundException, IOException {
|
public TarFile(String name) throws FileNotFoundException, IOException {
|
||||||
this(new File(name));
|
this(new File(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads tar entries.
|
* Loads tar entries.
|
||||||
* @throws FileNotFoundException if the file does not exist.
|
* @throws FileNotFoundException if the file does not exist.
|
||||||
|
@ -143,13 +144,13 @@ public class TarFile {
|
||||||
private void loadTarEntries() throws FileNotFoundException, IOException {
|
private void loadTarEntries() throws FileNotFoundException, IOException {
|
||||||
InputStream stream = getInputStream();
|
InputStream stream = getInputStream();
|
||||||
blockHeaders = new Vector();
|
blockHeaders = new Vector();
|
||||||
|
|
||||||
// now read all the block headers
|
// now read all the block headers
|
||||||
byte[] blockData = readBlock(stream);
|
byte[] blockData = readBlock(stream);
|
||||||
|
|
||||||
// while end of stream is not reached, extract block headers
|
// while end of stream is not reached, extract block headers
|
||||||
while (blockData.length != 0) {
|
while (blockData.length != 0) {
|
||||||
|
|
||||||
// extract the header from the block
|
// extract the header from the block
|
||||||
TarEntry header = extractBlockHeader(blockData);
|
TarEntry header = extractBlockHeader(blockData);
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ public class TarFile {
|
||||||
|
|
||||||
// determine how many blocks make up the contents of the file
|
// determine how many blocks make up the contents of the file
|
||||||
long fileSize = 0;
|
long fileSize = 0;
|
||||||
|
|
||||||
// Bug 139207: Browsing into some tar archives failed
|
// Bug 139207: Browsing into some tar archives failed
|
||||||
// The reason was that the last entry in the file did not necessarily have an empty string as the name
|
// The reason was that the last entry in the file did not necessarily have an empty string as the name
|
||||||
// of the entry and so the header is not null. The tar format does not guarantee an empty name.
|
// of the entry and so the header is not null. The tar format does not guarantee an empty name.
|
||||||
|
@ -170,10 +171,10 @@ public class TarFile {
|
||||||
catch (NumberFormatException e) {
|
catch (NumberFormatException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add header only if the size is valid
|
// add header only if the size is valid
|
||||||
blockHeaders.add(header);
|
blockHeaders.add(header);
|
||||||
|
|
||||||
int numFileBlocks = (int)(fileSize / ITarConstants.BLOCK_SIZE);
|
int numFileBlocks = (int)(fileSize / ITarConstants.BLOCK_SIZE);
|
||||||
numFileBlocks += (fileSize % ITarConstants.BLOCK_SIZE) > 0 ? 1 : 0;
|
numFileBlocks += (fileSize % ITarConstants.BLOCK_SIZE) > 0 ? 1 : 0;
|
||||||
|
|
||||||
|
@ -192,7 +193,7 @@ public class TarFile {
|
||||||
|
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the input stream for the tar file.
|
* Gets the input stream for the tar file.
|
||||||
* @return the input stream for the tar file.
|
* @return the input stream for the tar file.
|
||||||
|
@ -203,7 +204,7 @@ public class TarFile {
|
||||||
FileInputStream stream = new FileInputStream(file);
|
FileInputStream stream = new FileInputStream(file);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the next block.
|
* Reads the next block.
|
||||||
* @param stream the input stream of the tar file.
|
* @param stream the input stream of the tar file.
|
||||||
|
@ -218,7 +219,7 @@ public class TarFile {
|
||||||
|
|
||||||
for (int i = 0; i < ITarConstants.BLOCK_SIZE; i++) {
|
for (int i = 0; i < ITarConstants.BLOCK_SIZE; i++) {
|
||||||
byteRead = stream.read();
|
byteRead = stream.read();
|
||||||
|
|
||||||
if (byteRead != -1) {
|
if (byteRead != -1) {
|
||||||
blockData[i] = (byte)byteRead;
|
blockData[i] = (byte)byteRead;
|
||||||
}
|
}
|
||||||
|
@ -234,16 +235,16 @@ public class TarFile {
|
||||||
|
|
||||||
return blockData;
|
return blockData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the header of a block given the block data.
|
* Extracts the header of a block given the block data.
|
||||||
* @param blockData the block data.
|
* @param blockData the block data.
|
||||||
* @return the header of the block, or <code>null</code> if the block indicates end of file.
|
* @return the header of the block, or <code>null</code> if the block indicates end of file.
|
||||||
*/
|
*/
|
||||||
private TarEntry extractBlockHeader(byte[] blockData) throws IOException {
|
private TarEntry extractBlockHeader(byte[] blockData) throws IOException {
|
||||||
|
|
||||||
TarEntry entry = new TarEntry(blockData);
|
TarEntry entry = new TarEntry(blockData);
|
||||||
|
|
||||||
// if the name of the entry is an empty string, it means we have reached end of file
|
// if the name of the entry is an empty string, it means we have reached end of file
|
||||||
// so just return null
|
// so just return null
|
||||||
if (entry.getName().equals("")) { //$NON-NLS-1$
|
if (entry.getName().equals("")) { //$NON-NLS-1$
|
||||||
|
@ -253,7 +254,7 @@ public class TarFile {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an enumeration of the tar file entries.
|
* Returns an enumeration of the tar file entries.
|
||||||
* @return an enumeration of the tar file entries.
|
* @return an enumeration of the tar file entries.
|
||||||
|
@ -261,7 +262,7 @@ public class TarFile {
|
||||||
public Enumeration entries() {
|
public Enumeration entries() {
|
||||||
return blockHeaders.elements();
|
return blockHeaders.elements();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of entries in the tar file.
|
* Returns the number of entries in the tar file.
|
||||||
* @return the number of entries in the tar file.
|
* @return the number of entries in the tar file.
|
||||||
|
@ -269,33 +270,33 @@ public class TarFile {
|
||||||
public int size() {
|
public int size() {
|
||||||
return blockHeaders.size();
|
return blockHeaders.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tar file entry with that name, or <code>null</code> if not found.
|
* Returns the tar file entry with that name, or <code>null</code> if not found.
|
||||||
* @param name the name of the entry.
|
* @param name the name of the entry.
|
||||||
* @return the tar file entry, or <code>null</code> if not found.
|
* @return the tar file entry, or <code>null</code> if not found.
|
||||||
*/
|
*/
|
||||||
public TarEntry getEntry(String name) {
|
public TarEntry getEntry(String name) {
|
||||||
|
|
||||||
// TODO: could we maybe keep a hash instead to make it faster?
|
// TODO: could we maybe keep a hash instead to make it faster?
|
||||||
// The hash could be keyed by names. But tars do allow headers with the same name.
|
// The hash could be keyed by names. But tars do allow headers with the same name.
|
||||||
// Research this.
|
// Research this.
|
||||||
Enumeration headers = entries();
|
Enumeration headers = entries();
|
||||||
|
|
||||||
// go through all block headers
|
// go through all block headers
|
||||||
while (headers.hasMoreElements()) {
|
while (headers.hasMoreElements()) {
|
||||||
TarEntry entry = (TarEntry)(headers.nextElement());
|
TarEntry entry = (TarEntry)(headers.nextElement());
|
||||||
String entryName = entry.getName();
|
String entryName = entry.getName();
|
||||||
|
|
||||||
// if name of entry matches the given name, then that is the entry we are looking for
|
// if name of entry matches the given name, then that is the entry we are looking for
|
||||||
if (entryName.equals(name) || entryName.equals(name + "/")) { //$NON-NLS-1$
|
if (entryName.equals(name) || entryName.equals(name + "/")) { //$NON-NLS-1$
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the input stream of the data in the given entry.
|
* Returns the input stream of the data in the given entry.
|
||||||
* @param entry the entry.
|
* @param entry the entry.
|
||||||
|
@ -304,21 +305,21 @@ public class TarFile {
|
||||||
*/
|
*/
|
||||||
public InputStream getInputStream(TarEntry entry) throws IOException {
|
public InputStream getInputStream(TarEntry entry) throws IOException {
|
||||||
InputStream stream = getInputStream();
|
InputStream stream = getInputStream();
|
||||||
|
|
||||||
// now read all the block headers
|
// now read all the block headers
|
||||||
byte[] blockData = readBlock(stream);
|
byte[] blockData = readBlock(stream);
|
||||||
|
|
||||||
// while end of stream is not reached, extract block headers
|
// while end of stream is not reached, extract block headers
|
||||||
while (blockData.length != 0) {
|
while (blockData.length != 0) {
|
||||||
|
|
||||||
// extract the header from the block
|
// extract the header from the block
|
||||||
TarEntry header = extractBlockHeader(blockData);
|
TarEntry header = extractBlockHeader(blockData);
|
||||||
|
|
||||||
// if header is not null, we add it to our list of headers
|
// if header is not null, we add it to our list of headers
|
||||||
if (header != null) {
|
if (header != null) {
|
||||||
|
|
||||||
long fileSize = 0;
|
long fileSize = 0;
|
||||||
|
|
||||||
// Bug 139207: Browsing into some tar archives failed
|
// Bug 139207: Browsing into some tar archives failed
|
||||||
// The reason was that the last entry in the file did not necessarily have an empty string as the name
|
// The reason was that the last entry in the file did not necessarily have an empty string as the name
|
||||||
// of the entry and so the header is not null. The tar format does not guarantee an empty name.
|
// of the entry and so the header is not null. The tar format does not guarantee an empty name.
|
||||||
|
@ -333,7 +334,7 @@ public class TarFile {
|
||||||
|
|
||||||
// if the header name does not match the entry name
|
// if the header name does not match the entry name
|
||||||
if (!header.getName().equals(entry.getName())) {
|
if (!header.getName().equals(entry.getName())) {
|
||||||
|
|
||||||
// determine how many blocks make up the contents of the file
|
// determine how many blocks make up the contents of the file
|
||||||
int numFileBlocks = (int)(fileSize / ITarConstants.BLOCK_SIZE);
|
int numFileBlocks = (int)(fileSize / ITarConstants.BLOCK_SIZE);
|
||||||
numFileBlocks += (fileSize % ITarConstants.BLOCK_SIZE) > 0 ? 1 : 0;
|
numFileBlocks += (fileSize % ITarConstants.BLOCK_SIZE) > 0 ? 1 : 0;
|
||||||
|
@ -356,7 +357,7 @@ public class TarFile {
|
||||||
// now read the next block
|
// now read the next block
|
||||||
blockData = readBlock(stream);
|
blockData = readBlock(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* component that contains this file: David McKnight, Kushal Munir,
|
* component that contains this file: David McKnight, Kushal Munir,
|
||||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
|
||||||
* Martin Oberhuber (Wind River) - [cleanup] Move from internal to fix API leakage
|
* Martin Oberhuber (Wind River) - [cleanup] Move from internal to fix API leakage
|
||||||
|
@ -24,8 +24,9 @@ import java.io.OutputStream;
|
||||||
import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants;
|
import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements an output stream filter for writing files in the
|
* This class implements an output stream filter for writing files in the tar
|
||||||
* tar file format.
|
* file format.
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class TarOutputStream extends OutputStream {
|
public class TarOutputStream extends OutputStream {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue