Created
August 2, 2011 23:39
-
-
Save kevinsawicki/1121516 to your computer and use it in GitHub Desktop.
Add downloads to a GitHub repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import org.eclipse.egit.github.core.Download; | |
import org.eclipse.egit.github.core.RepositoryId; | |
import org.eclipse.egit.github.core.client.GitHubClient; | |
import org.eclipse.egit.github.core.service.DownloadService; | |
/** | |
* Uploads a file to be made available as a repository download | |
*/ | |
public class UploadFile { | |
public static void main(String... args) throws IOException { | |
GitHubClient client = new GitHubClient(); | |
client.setCredentials("user", "secret"); | |
// Owner and name of repository such as 'rails/rails' | |
RepositoryId repository = new RepositoryId("user", "project"); | |
DownloadService service = new DownloadService(client); | |
File file = File.createTempFile("download", ".txt"); | |
PrintWriter writer = new PrintWriter(file); | |
writer.println("Content of the file"); | |
writer.close(); | |
Download download = new Download(); | |
download.setDescription("Attaching some file"); | |
download.setName(file.getName()); | |
download.setSize(file.length()); | |
service.createDownload(repository, download, file); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.IOException; | |
import org.eclipse.egit.github.core.Download; | |
import org.eclipse.egit.github.core.RepositoryId; | |
import org.eclipse.egit.github.core.client.GitHubClient; | |
import org.eclipse.egit.github.core.service.DownloadService; | |
/** | |
* Uploads a String to be made available as a repository download | |
*/ | |
public class UploadStream { | |
public static void main(String... args) throws IOException { | |
GitHubClient client = new GitHubClient(); | |
client.setCredentials("user", "secret"); | |
// Owner and name of repository such as 'rails/rails' | |
RepositoryId repository = new RepositoryId("user", "project"); | |
DownloadService service = new DownloadService(client); | |
byte[] content = "download content".getBytes("UTF-8"); | |
Download download = new Download(); | |
download.setDescription("Attaching some text"); | |
download.setName("simple.txt"); | |
download.setSize(content.length); | |
ByteArrayInputStream stream = new ByteArrayInputStream(content); | |
service.createDownload(repository, download, stream, content.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Documentation for the downloads API is available here