I am trying to export whole repository in zip format .I am not able to find anything related to exporting a folder or repository in svnkit.
Asked
Active
Viewed 489 times
-1
-
can someone explain why this question got -1 votes ??? – WorkaroundNewbie Feb 19 '16 at 15:48
1 Answers
1
I have never tried zipping the whole repository using org.tmatesoft.svnkit. But I have an utility that zips files from a local folder. So if you copy the remote repository locally (into a temp directory), you should be able to zip it using the following class. It needs 2 values, starting folder path and the full, zip file name.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipFolder {
private String startingFolderPath;
private String outputZipFilePath;
private List<String> fileList;
/**
* Zip files
*/
public void zipFiles(){
byte[] buffer = new byte[1024];
try{
if (fileList == null) {
fileList = new ArrayList<String>();
generateFileList(new File(startingFolderPath));
}
System.out.println("File Count:" + fileList.size());
FileOutputStream fos = new FileOutputStream(outputZipFilePath);
ZipOutputStream zos = new ZipOutputStream(fos);
System.out.println("Output to Zip : " + outputZipFilePath);
for(String file : fileList){
System.out.println("File Included : " + file);
ZipEntry ze= new ZipEntry(file);
zos.putNextEntry(ze);
FileInputStream in =
new FileInputStream(startingFolderPath + File.separator + file);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
}
zos.closeEntry();
//remember close it
zos.close();
System.out.println("Done");
}catch(IOException ex){
ex.printStackTrace();
}
}
/**
* Traverse a directory and get all files,
* and add the file into fileList
* @param node file or directory
*/
public void generateFileList(File node) throws IOException {
//add file only
if(node.isFile()){
fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
}
if(node.isDirectory()){
String[] subNote = node.list();
for(String filename : subNote){
generateFileList(new File(node, filename));
}
}
}
/**
* Format the file path for zip
* @param file file path
* @return Formatted file path
*/
private String generateZipEntry(String file){
return file.substring(startingFolderPath.length()+1, file.length());
}
public void setStartingFolderPath(String startingFolderPath) {
this.startingFolderPath = startingFolderPath;
}
public void setOutputZipFilePath(String outputZipFilePath) {
this.outputZipFilePath = outputZipFilePath;
}
}

Shriram M.
- 383
- 1
- 7