if (e == null) continue; final String name = e.getName(); if (".".equals(name) || "..".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (i != o) entries[o] = e; e.encodeName(nameEncoder); o++;
/** * Reads the target of a symlink as a string. This default implementation * fully reads the entry's input stream and converts it to a normalized * string. Subclasses may override to provide more specialized * implementations. * * @param entry * to read * @return the entry's content as a normalized string * @throws java.io.IOException * if the entry cannot be read or does not denote a symlink * @since 4.6 */ protected String readSymlinkTarget(Entry entry) throws IOException { if (!entry.getMode().equals(FileMode.SYMLINK)) { throw new java.nio.file.NotLinkException(entry.getName()); } long length = entry.getLength(); byte[] content = new byte[(int) length]; try (InputStream is = entry.openInputStream()) { int bytesRead = IO.readFully(is, content, 0); return FS.detect() .normalize(RawParseUtils.decode(content, 0, bytesRead)); } }
if (e == null) continue; final String name = e.getName(); if (".".equals(name) || "..".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (i != o) entries[o] = e; e.encodeName(nameEncoder); o++;
if (e == null) continue; final String name = e.getName(); if (".".equals(name) || "..".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (i != o) entries[o] = e; e.encodeName(nameEncoder); o++;
final InputStream lenIs = filterClean(e.openInputStream(), opType); try {
/** * Get submodule id using the repository at the location of the entry * relative to the directory. * * @param directory * a {@link java.io.File} object. * @param e * a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry} * object. * @return non-null submodule id */ protected byte[] idSubmodule(File directory, Entry e) { try (Repository submoduleRepo = SubmoduleWalk.getSubmoduleRepository( directory, e.getName(), repository != null ? repository.getFS() : FS.DETECTED)) { if (submoduleRepo == null) { return zeroid; } ObjectId head = submoduleRepo.resolve(Constants.HEAD); if (head == null) { return zeroid; } byte[] id = new byte[Constants.OBJECT_ID_LENGTH]; head.copyRawTo(id, 0); return id; } catch (IOException exception) { return zeroid; } }
try { submoduleRepo = SubmoduleWalk.getSubmoduleRepository(directory, e.getName()); } catch (IOException exception) { return zeroid;
private InputStream possiblyFilteredInputStream(final Entry e, final InputStream is, final long len, OperationType opType) throws IOException { if (getCleanFilterCommand() == null && getEolStreamType(opType) == EolStreamType.DIRECT) { canonLen = len; return is; } if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); rawbuf = filterClean(rawbuf.array(), rawbuf.limit(), opType); canonLen = rawbuf.limit(); return new ByteArrayInputStream(rawbuf.array(), 0, (int) canonLen); } if (getCleanFilterCommand() == null && isBinary(e)) { canonLen = len; return is; } final InputStream lenIs = filterClean(e.openInputStream(), opType); try { canonLen = computeLength(lenIs); } finally { safeClose(lenIs); } return filterClean(is, opType); }
/** * Obtain an input stream to read the file content. * <p> * Efficient implementations are not required. The caller will usually * obtain the stream only once per entry, if at all. * <p> * The input stream should not use buffering if the implementation can avoid * it. The caller will buffer as necessary to perform efficient block IO * operations. * <p> * The caller will close the stream once complete. * * @return a stream to read from the file. * @throws java.io.IOException * the file could not be opened for reading. */ public InputStream openEntryStream() throws IOException { InputStream rawis = current().openInputStream(); if (getCleanFilterCommand() == null && getEolStreamType() == EolStreamType.DIRECT) return rawis; else return filterClean(rawis); }
/** * Reads the target of a symlink as a string. This default implementation * fully reads the entry's input stream and converts it to a normalized * string. Subclasses may override to provide more specialized * implementations. * * @param entry * to read * @return the entry's content as a normalized string * @throws java.io.IOException * if the entry cannot be read or does not denote a symlink * @since 4.6 */ protected String readSymlinkTarget(Entry entry) throws IOException { if (!entry.getMode().equals(FileMode.SYMLINK)) { throw new java.nio.file.NotLinkException(entry.getName()); } long length = entry.getLength(); byte[] content = new byte[(int) length]; try (InputStream is = entry.openInputStream()) { int bytesRead = IO.readFully(is, content, 0); return FS.detect() .normalize(RawParseUtils.decode(content, 0, bytesRead)); } }
/** * Get the filtered input length of this entry * * @return size of the content, in bytes * @throws IOException */ public long getEntryContentLength() throws IOException { if (canonLen == -1) { long rawLen = getEntryLength(); if (rawLen == 0) canonLen = 0; InputStream is = current().openInputStream(); try { // canonLen gets updated here possiblyFilteredInputStream(current(), is, current() .getLength()); } finally { safeClose(is); } } return canonLen; }
/** * Obtain an input stream to read the file content. * <p> * Efficient implementations are not required. The caller will usually * obtain the stream only once per entry, if at all. * <p> * The input stream should not use buffering if the implementation can avoid * it. The caller will buffer as necessary to perform efficient block IO * operations. * <p> * The caller will close the stream once complete. * * @return a stream to read from the file. * @throws IOException * the file could not be opened for reading. */ public InputStream openEntryStream() throws IOException { InputStream rawis = current().openInputStream(); if (getCleanFilterCommand() == null && getEolStreamType() == EolStreamType.DIRECT) return rawis; else return filterClean(rawis); }
/** * Get the filtered input length of this entry * * @return size of the content, in bytes * @throws java.io.IOException */ public long getEntryContentLength() throws IOException { if (canonLen == -1) { long rawLen = getEntryLength(); if (rawLen == 0) canonLen = 0; InputStream is = current().openInputStream(); try { // canonLen gets updated here possiblyFilteredInputStream(current(), is, current() .getLength()); } finally { safeClose(is); } } return canonLen; }
private byte[] idBufferBlob(Entry e) { try { final InputStream is = e.openInputStream(); if (is == null) return zeroid; try { state.initializeReadBuffer(); final long len = e.getLength(); InputStream filteredIs = possiblyFilteredInputStream(e, is, len, OperationType.CHECKIN_OP); return computeHash(filteredIs, canonLen); } finally { safeClose(is); } } catch (IOException err) { // Can't read the file? Don't report the failure either. return zeroid; } }
private byte[] idBufferBlob(final Entry e) { try { final InputStream is = e.openInputStream(); if (is == null) return zeroid; try { state.initializeDigestAndReadBuffer(); final long len = e.getLength(); InputStream filteredIs = possiblyFilteredInputStream(e, is, len, OperationType.CHECKIN_OP); return computeHash(filteredIs, canonLen); } finally { safeClose(is); } } catch (IOException err) { // Can't read the file? Don't report the failure either. return zeroid; } }
void encodeName(CharsetEncoder enc) { final ByteBuffer b; try { b = enc.encode(CharBuffer.wrap(getName())); } catch (CharacterCodingException e) { // This should so never happen. throw new RuntimeException(MessageFormat.format( JGitText.get().unencodeableFile, getName())); } encodedNameLen = b.limit(); if (b.hasArray() && b.arrayOffset() == 0) encodedName = b.array(); else b.get(encodedName = new byte[encodedNameLen]); }
void encodeName(final CharsetEncoder enc) { final ByteBuffer b; try { b = enc.encode(CharBuffer.wrap(getName())); } catch (CharacterCodingException e) { // This should so never happen. throw new RuntimeException(MessageFormat.format( JGitText.get().unencodeableFile, getName())); } encodedNameLen = b.limit(); if (b.hasArray() && b.arrayOffset() == 0) encodedName = b.array(); else b.get(encodedName = new byte[encodedNameLen]); }
/** * Get the raw byte length of this entry. * * @return size of this file, in bytes. */ public long getEntryLength() { return current().getLength(); }