Search in sources :

Example 1 with Blob

use of org.eclipse.egit.github.core.Blob in project camel by apache.

the class GetCommitFileProducer method process.

public void process(Exchange exchange) throws Exception {
    CommitFile file = exchange.getIn().getBody(CommitFile.class);
    Blob response = dataService.getBlob(getRepository(), file.getSha());
    String text = response.getContent();
    // base64 encoding is required, then must be explicitly requested
    if (response.getEncoding().equals(Blob.ENCODING_BASE64) && encoding != null && encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
        text = new String(Base64.decodeBase64(text));
    }
    // copy the header of in message to the out message
    exchange.getOut().copyFrom(exchange.getIn());
    exchange.getOut().setBody(text);
}
Also used : Blob(org.eclipse.egit.github.core.Blob) CommitFile(org.eclipse.egit.github.core.CommitFile)

Example 2 with Blob

use of org.eclipse.egit.github.core.Blob in project Bitocle by mthli.

the class WebViewTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    GitHubClient client = fragment.getClient();
    RepositoryId id = RepositoryId.create(owner, name);
    DataService dataService = new DataService(client);
    MarkdownService markdownService = new MarkdownService(client);
    Blob blob;
    try {
        blob = dataService.getBlob(id, sha);
    } catch (IOException i) {
        return false;
    }
    if (isCancelled()) {
        return false;
    }
    String base64 = blob.getContent();
    if (!MimeType.isImage(filename)) {
        byte[] bytes = EncodingUtils.fromBase64(base64);
        content = new String(bytes);
    }
    if (MimeType.isImage(filename)) {
        String imageUrl = GetImage.getImageUrl(base64, MimeType.getImageExtension(filename));
        image = GetImage.getImage(imageUrl);
    } else if (MimeType.isMarkdown(filename)) {
        try {
            content = markdownService.getHtml(content, MarkdownService.MODE_GFM);
            content = StyleMarkdown.styleMarkdown(content);
        } catch (IOException i) {
            return false;
        }
    } else {
        content = SyntaxCode.syntaxCode(content, css);
    }
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) Blob(org.eclipse.egit.github.core.Blob) MarkdownService(org.eclipse.egit.github.core.service.MarkdownService) IOException(java.io.IOException) RepositoryId(org.eclipse.egit.github.core.RepositoryId) DataService(org.eclipse.egit.github.core.service.DataService)

Aggregations

Blob (org.eclipse.egit.github.core.Blob)2 IOException (java.io.IOException)1 CommitFile (org.eclipse.egit.github.core.CommitFile)1 RepositoryId (org.eclipse.egit.github.core.RepositoryId)1 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)1 DataService (org.eclipse.egit.github.core.service.DataService)1 MarkdownService (org.eclipse.egit.github.core.service.MarkdownService)1