protected static String createBlob(DataService service, RepositoryId repository, String prefix, String path) throws Exception { File file = new File(prefix, path); final long length = file.length(); final int size = length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length; ByteArrayOutputStream output = new ByteArrayOutputStream(size); FileInputStream stream = new FileInputStream(file); try { final byte[] buffer = new byte[8192]; int read; while ((read = stream.read(buffer)) != -1) output.write(buffer, 0, read); Blob blob = new Blob().setEncoding(Blob.ENCODING_BASE64); String encoded = EncodingUtils.toBase64(output.toByteArray()); blob.setContent(encoded); return service.createBlob(repository, blob); } finally { stream.close(); } }
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(); // By default, if blob encoding is base64 then we convert to UTF-8. If // 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); }
public static TreeEntry createTreeFromString(String prefix, String name, String content, DataService serv, RepositoryId id) throws Exception { TreeEntry entry = new TreeEntry(); entry.setPath(prefix + name); entry.setType(TreeEntry.TYPE_BLOB); entry.setMode(TreeEntry.MODE_BLOB); Blob blob = new Blob().setEncoding(Blob.ENCODING_UTF8); blob.setContent(content); entry.setSha(serv.createBlob(id, blob)); return entry; } }
Blob blob = new Blob().setEncoding(ENCODING_BASE64); String encoded = EncodingUtils.toBase64(output.toByteArray()); blob.setContent(encoded);
Blob blob = new Blob().setEncoding(ENCODING_BASE64); String encoded = EncodingUtils.toBase64(output.toByteArray()); blob.setContent(encoded);
if (!dryRun) try { entry.setSha(service.createBlob(repository, new Blob() .setEncoding(ENCODING_BASE64).setContent(""))); } catch (IOException e) { throw new MojoExecutionException(
if (!dryRun) try { entry.setSha(service.createBlob(repository, new Blob() .setEncoding(ENCODING_BASE64).setContent(""))); } catch (IOException e) { throw new MojoExecutionException(