repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/Piece.java | Piece.record | public void record(ByteBuffer block, int offset) {
if (this.data == null) {
// TODO: remove cast to int when large ByteBuffer support is
// implemented in Java.
this.data = ByteBuffer.allocate((int) this.length);
}
int pos = block.position();
this.data.position(offset);
this.data.put(block);
block.position(pos);
} | java | public void record(ByteBuffer block, int offset) {
if (this.data == null) {
// TODO: remove cast to int when large ByteBuffer support is
// implemented in Java.
this.data = ByteBuffer.allocate((int) this.length);
}
int pos = block.position();
this.data.position(offset);
this.data.put(block);
block.position(pos);
} | [
"public",
"void",
"record",
"(",
"ByteBuffer",
"block",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"this",
".",
"data",
"==",
"null",
")",
"{",
"// TODO: remove cast to int when large ByteBuffer support is",
"// implemented in Java.",
"this",
".",
"data",
"=",
"By... | Record the given block at the given offset in this piece.
@param block The ByteBuffer containing the block data.
@param offset The block offset in this piece. | [
"Record",
"the",
"given",
"block",
"at",
"the",
"given",
"offset",
"in",
"this",
"piece",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/Piece.java#L234-L245 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/Piece.java | Piece.compareTo | public int compareTo(Piece other) {
// return true for the same pieces, otherwise sort by time seen, then by index;
if (this.equals(other)) {
return 0;
} else if (this.seen == other.seen) {
return new Integer(this.index).compareTo(other.index);
} else if (this.seen < other.seen) {
return -1;
} else {
return 1;
}
} | java | public int compareTo(Piece other) {
// return true for the same pieces, otherwise sort by time seen, then by index;
if (this.equals(other)) {
return 0;
} else if (this.seen == other.seen) {
return new Integer(this.index).compareTo(other.index);
} else if (this.seen < other.seen) {
return -1;
} else {
return 1;
}
} | [
"public",
"int",
"compareTo",
"(",
"Piece",
"other",
")",
"{",
"// return true for the same pieces, otherwise sort by time seen, then by index;",
"if",
"(",
"this",
".",
"equals",
"(",
"other",
")",
")",
"{",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"this",
"... | Piece comparison function for ordering pieces based on their
availability.
@param other The piece to compare with, should not be <em>null</em>. | [
"Piece",
"comparison",
"function",
"for",
"ordering",
"pieces",
"based",
"on",
"their",
"availability",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/Piece.java#L281-L292 | train |
mpetazzoni/ttorrent | ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java | TrackedTorrent.addPeer | public void addPeer(TrackedPeer peer) {
this.peers.put(new PeerUID(peer.getAddress(), this.getHexInfoHash()), peer);
} | java | public void addPeer(TrackedPeer peer) {
this.peers.put(new PeerUID(peer.getAddress(), this.getHexInfoHash()), peer);
} | [
"public",
"void",
"addPeer",
"(",
"TrackedPeer",
"peer",
")",
"{",
"this",
".",
"peers",
".",
"put",
"(",
"new",
"PeerUID",
"(",
"peer",
".",
"getAddress",
"(",
")",
",",
"this",
".",
"getHexInfoHash",
"(",
")",
")",
",",
"peer",
")",
";",
"}"
] | Add a peer exchanging on this torrent.
@param peer The new Peer involved with this torrent. | [
"Add",
"a",
"peer",
"exchanging",
"on",
"this",
"torrent",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java#L105-L107 | train |
mpetazzoni/ttorrent | ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java | TrackedTorrent.getSomePeers | public List<Peer> getSomePeers(Peer peer) {
List<Peer> peers = new LinkedList<Peer>();
// Extract answerPeers random peers
List<TrackedPeer> candidates = new LinkedList<TrackedPeer>(this.peers.values());
Collections.shuffle(candidates);
int count = 0;
for (TrackedPeer candidate : candidates) {
// Don't include the requesting peer in the answer.
if (peer != null && peer.looksLike(candidate)) {
continue;
}
// Only serve at most ANSWER_NUM_PEERS peers
if (count++ > this.answerPeers) {
break;
}
peers.add(candidate);
}
return peers;
} | java | public List<Peer> getSomePeers(Peer peer) {
List<Peer> peers = new LinkedList<Peer>();
// Extract answerPeers random peers
List<TrackedPeer> candidates = new LinkedList<TrackedPeer>(this.peers.values());
Collections.shuffle(candidates);
int count = 0;
for (TrackedPeer candidate : candidates) {
// Don't include the requesting peer in the answer.
if (peer != null && peer.looksLike(candidate)) {
continue;
}
// Only serve at most ANSWER_NUM_PEERS peers
if (count++ > this.answerPeers) {
break;
}
peers.add(candidate);
}
return peers;
} | [
"public",
"List",
"<",
"Peer",
">",
"getSomePeers",
"(",
"Peer",
"peer",
")",
"{",
"List",
"<",
"Peer",
">",
"peers",
"=",
"new",
"LinkedList",
"<",
"Peer",
">",
"(",
")",
";",
"// Extract answerPeers random peers",
"List",
"<",
"TrackedPeer",
">",
"candid... | Get a list of peers we can return in an announce response for this
torrent.
@param peer The peer making the request, so we can exclude it from the
list of returned peers.
@return A list of peers we can include in an announce response. | [
"Get",
"a",
"list",
"of",
"peers",
"we",
"can",
"return",
"in",
"an",
"announce",
"response",
"for",
"this",
"torrent",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java#L238-L261 | train |
mpetazzoni/ttorrent | ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java | TrackedTorrent.load | public static TrackedTorrent load(File torrent) throws IOException {
TorrentMetadata torrentMetadata = new TorrentParser().parseFromFile(torrent);
return new TrackedTorrent(torrentMetadata.getInfoHash());
} | java | public static TrackedTorrent load(File torrent) throws IOException {
TorrentMetadata torrentMetadata = new TorrentParser().parseFromFile(torrent);
return new TrackedTorrent(torrentMetadata.getInfoHash());
} | [
"public",
"static",
"TrackedTorrent",
"load",
"(",
"File",
"torrent",
")",
"throws",
"IOException",
"{",
"TorrentMetadata",
"torrentMetadata",
"=",
"new",
"TorrentParser",
"(",
")",
".",
"parseFromFile",
"(",
"torrent",
")",
";",
"return",
"new",
"TrackedTorrent",... | Load a tracked torrent from the given torrent file.
@param torrent The abstract {@link File} object representing the
<tt>.torrent</tt> file to load.
@throws IOException When the torrent file cannot be read. | [
"Load",
"a",
"tracked",
"torrent",
"from",
"the",
"given",
"torrent",
"file",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-tracker/src/main/java/com/turn/ttorrent/tracker/TrackedTorrent.java#L270-L274 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.addTorrent | public TorrentManager addTorrent(String dotTorrentFilePath, String downloadDirPath) throws IOException {
return addTorrent(dotTorrentFilePath, downloadDirPath, FairPieceStorageFactory.INSTANCE);
} | java | public TorrentManager addTorrent(String dotTorrentFilePath, String downloadDirPath) throws IOException {
return addTorrent(dotTorrentFilePath, downloadDirPath, FairPieceStorageFactory.INSTANCE);
} | [
"public",
"TorrentManager",
"addTorrent",
"(",
"String",
"dotTorrentFilePath",
",",
"String",
"downloadDirPath",
")",
"throws",
"IOException",
"{",
"return",
"addTorrent",
"(",
"dotTorrentFilePath",
",",
"downloadDirPath",
",",
"FairPieceStorageFactory",
".",
"INSTANCE",
... | Adds torrent to storage, validate downloaded files and start seeding and leeching the torrent
@param dotTorrentFilePath path to torrent metadata file
@param downloadDirPath path to directory where downloaded files are placed
@return {@link TorrentManager} instance for monitoring torrent state
@throws IOException if IO error occurs in reading metadata file | [
"Adds",
"torrent",
"to",
"storage",
"validate",
"downloaded",
"files",
"and",
"start",
"seeding",
"and",
"leeching",
"the",
"torrent"
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L129-L131 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.addTorrent | public TorrentManager addTorrent(String dotTorrentFilePath, String downloadDirPath, List<TorrentListener> listeners) throws IOException {
return addTorrent(dotTorrentFilePath, downloadDirPath, FairPieceStorageFactory.INSTANCE, listeners);
} | java | public TorrentManager addTorrent(String dotTorrentFilePath, String downloadDirPath, List<TorrentListener> listeners) throws IOException {
return addTorrent(dotTorrentFilePath, downloadDirPath, FairPieceStorageFactory.INSTANCE, listeners);
} | [
"public",
"TorrentManager",
"addTorrent",
"(",
"String",
"dotTorrentFilePath",
",",
"String",
"downloadDirPath",
",",
"List",
"<",
"TorrentListener",
">",
"listeners",
")",
"throws",
"IOException",
"{",
"return",
"addTorrent",
"(",
"dotTorrentFilePath",
",",
"download... | Adds torrent to storage with specified listeners, validate downloaded files and start seeding and leeching the torrent
@param dotTorrentFilePath path to torrent metadata file
@param downloadDirPath path to directory where downloaded files are placed
@param listeners specified listeners
@return {@link TorrentManager} instance for monitoring torrent state
@throws IOException if IO error occurs in reading metadata file | [
"Adds",
"torrent",
"to",
"storage",
"with",
"specified",
"listeners",
"validate",
"downloaded",
"files",
"and",
"start",
"seeding",
"and",
"leeching",
"the",
"torrent"
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L142-L144 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.addTorrent | public TorrentManager addTorrent(TorrentMetadataProvider metadataProvider, PieceStorage pieceStorage) throws IOException {
return addTorrent(metadataProvider, pieceStorage, Collections.<TorrentListener>emptyList());
} | java | public TorrentManager addTorrent(TorrentMetadataProvider metadataProvider, PieceStorage pieceStorage) throws IOException {
return addTorrent(metadataProvider, pieceStorage, Collections.<TorrentListener>emptyList());
} | [
"public",
"TorrentManager",
"addTorrent",
"(",
"TorrentMetadataProvider",
"metadataProvider",
",",
"PieceStorage",
"pieceStorage",
")",
"throws",
"IOException",
"{",
"return",
"addTorrent",
"(",
"metadataProvider",
",",
"pieceStorage",
",",
"Collections",
".",
"<",
"Tor... | Adds torrent to storage with any storage and metadata source
@param metadataProvider specified metadata source
@param pieceStorage specified storage of pieces
@return {@link TorrentManager} instance for monitoring torrent state
@throws IOException if IO error occurs in reading metadata file | [
"Adds",
"torrent",
"to",
"storage",
"with",
"any",
"storage",
"and",
"metadata",
"source"
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L191-L193 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.addTorrent | public TorrentManager addTorrent(TorrentMetadataProvider metadataProvider,
PieceStorage pieceStorage,
List<TorrentListener> listeners) throws IOException {
TorrentMetadata torrentMetadata = metadataProvider.getTorrentMetadata();
EventDispatcher eventDispatcher = new EventDispatcher();
for (TorrentListener listener : listeners) {
eventDispatcher.addListener(listener);
}
final LoadedTorrentImpl loadedTorrent = new LoadedTorrentImpl(
new TorrentStatistic(),
metadataProvider,
torrentMetadata,
pieceStorage,
eventDispatcher);
if (pieceStorage.isFinished()) {
loadedTorrent.getTorrentStatistic().setLeft(0);
} else {
long left = calculateLeft(pieceStorage, torrentMetadata);
loadedTorrent.getTorrentStatistic().setLeft(left);
}
eventDispatcher.multicaster().validationComplete(pieceStorage.getAvailablePieces().cardinality(), torrentMetadata.getPiecesCount());
this.torrentsStorage.addTorrent(loadedTorrent.getTorrentHash().getHexInfoHash(), loadedTorrent);
forceAnnounceAndLogError(loadedTorrent, pieceStorage.isFinished() ? COMPLETED : STARTED);
logger.debug(String.format("Added torrent %s (%s)", loadedTorrent, loadedTorrent.getTorrentHash().getHexInfoHash()));
return new TorrentManagerImpl(eventDispatcher, loadedTorrent.getTorrentHash());
} | java | public TorrentManager addTorrent(TorrentMetadataProvider metadataProvider,
PieceStorage pieceStorage,
List<TorrentListener> listeners) throws IOException {
TorrentMetadata torrentMetadata = metadataProvider.getTorrentMetadata();
EventDispatcher eventDispatcher = new EventDispatcher();
for (TorrentListener listener : listeners) {
eventDispatcher.addListener(listener);
}
final LoadedTorrentImpl loadedTorrent = new LoadedTorrentImpl(
new TorrentStatistic(),
metadataProvider,
torrentMetadata,
pieceStorage,
eventDispatcher);
if (pieceStorage.isFinished()) {
loadedTorrent.getTorrentStatistic().setLeft(0);
} else {
long left = calculateLeft(pieceStorage, torrentMetadata);
loadedTorrent.getTorrentStatistic().setLeft(left);
}
eventDispatcher.multicaster().validationComplete(pieceStorage.getAvailablePieces().cardinality(), torrentMetadata.getPiecesCount());
this.torrentsStorage.addTorrent(loadedTorrent.getTorrentHash().getHexInfoHash(), loadedTorrent);
forceAnnounceAndLogError(loadedTorrent, pieceStorage.isFinished() ? COMPLETED : STARTED);
logger.debug(String.format("Added torrent %s (%s)", loadedTorrent, loadedTorrent.getTorrentHash().getHexInfoHash()));
return new TorrentManagerImpl(eventDispatcher, loadedTorrent.getTorrentHash());
} | [
"public",
"TorrentManager",
"addTorrent",
"(",
"TorrentMetadataProvider",
"metadataProvider",
",",
"PieceStorage",
"pieceStorage",
",",
"List",
"<",
"TorrentListener",
">",
"listeners",
")",
"throws",
"IOException",
"{",
"TorrentMetadata",
"torrentMetadata",
"=",
"metadat... | Adds torrent to storage with any storage, metadata source and specified listeners
@param metadataProvider specified metadata source
@param pieceStorage specified storage of pieces
@param listeners specified listeners
@return {@link TorrentManager} instance for monitoring torrent state
@throws IOException if IO error occurs in reading metadata file | [
"Adds",
"torrent",
"to",
"storage",
"with",
"any",
"storage",
"metadata",
"source",
"and",
"specified",
"listeners"
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L204-L231 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.removeTorrent | public void removeTorrent(String torrentHash) {
logger.debug("Stopping seeding " + torrentHash);
final Pair<SharedTorrent, LoadedTorrent> torrents = torrentsStorage.remove(torrentHash);
SharedTorrent torrent = torrents.first();
if (torrent != null) {
torrent.setClientState(ClientState.DONE);
torrent.closeFully();
}
List<SharingPeer> peers = getPeersForTorrent(torrentHash);
for (SharingPeer peer : peers) {
peer.unbind(true);
}
sendStopEvent(torrents.second(), torrentHash);
} | java | public void removeTorrent(String torrentHash) {
logger.debug("Stopping seeding " + torrentHash);
final Pair<SharedTorrent, LoadedTorrent> torrents = torrentsStorage.remove(torrentHash);
SharedTorrent torrent = torrents.first();
if (torrent != null) {
torrent.setClientState(ClientState.DONE);
torrent.closeFully();
}
List<SharingPeer> peers = getPeersForTorrent(torrentHash);
for (SharingPeer peer : peers) {
peer.unbind(true);
}
sendStopEvent(torrents.second(), torrentHash);
} | [
"public",
"void",
"removeTorrent",
"(",
"String",
"torrentHash",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Stopping seeding \"",
"+",
"torrentHash",
")",
";",
"final",
"Pair",
"<",
"SharedTorrent",
",",
"LoadedTorrent",
">",
"torrents",
"=",
"torrentsStorage",
"... | Removes specified torrent from storage.
@param torrentHash specified torrent hash | [
"Removes",
"specified",
"torrent",
"from",
"storage",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L266-L280 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.isSeed | public boolean isSeed(String hexInfoHash) {
SharedTorrent t = this.torrentsStorage.getTorrent(hexInfoHash);
return t != null && t.isComplete();
} | java | public boolean isSeed(String hexInfoHash) {
SharedTorrent t = this.torrentsStorage.getTorrent(hexInfoHash);
return t != null && t.isComplete();
} | [
"public",
"boolean",
"isSeed",
"(",
"String",
"hexInfoHash",
")",
"{",
"SharedTorrent",
"t",
"=",
"this",
".",
"torrentsStorage",
".",
"getTorrent",
"(",
"hexInfoHash",
")",
";",
"return",
"t",
"!=",
"null",
"&&",
"t",
".",
"isComplete",
"(",
")",
";",
"... | Tells whether we are a seed for the torrent we're sharing. | [
"Tells",
"whether",
"we",
"are",
"a",
"seed",
"for",
"the",
"torrent",
"we",
"re",
"sharing",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L513-L516 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.handleAnnounceResponse | @Override
public void handleAnnounceResponse(int interval, int complete, int incomplete, String hexInfoHash) {
final SharedTorrent sharedTorrent = this.torrentsStorage.getTorrent(hexInfoHash);
if (sharedTorrent != null) {
sharedTorrent.setSeedersCount(complete);
sharedTorrent.setLastAnnounceTime(System.currentTimeMillis());
}
setAnnounceInterval(interval);
} | java | @Override
public void handleAnnounceResponse(int interval, int complete, int incomplete, String hexInfoHash) {
final SharedTorrent sharedTorrent = this.torrentsStorage.getTorrent(hexInfoHash);
if (sharedTorrent != null) {
sharedTorrent.setSeedersCount(complete);
sharedTorrent.setLastAnnounceTime(System.currentTimeMillis());
}
setAnnounceInterval(interval);
} | [
"@",
"Override",
"public",
"void",
"handleAnnounceResponse",
"(",
"int",
"interval",
",",
"int",
"complete",
",",
"int",
"incomplete",
",",
"String",
"hexInfoHash",
")",
"{",
"final",
"SharedTorrent",
"sharedTorrent",
"=",
"this",
".",
"torrentsStorage",
".",
"g... | Handle an announce response event.
@param interval The announce interval requested by the tracker.
@param complete The number of seeders on this torrent.
@param incomplete The number of leechers on this torrent. | [
"Handle",
"an",
"announce",
"response",
"event",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L604-L612 | train |
mpetazzoni/ttorrent | ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java | CommunicationManager.handleDiscoveredPeers | @Override
public void handleDiscoveredPeers(List<Peer> peers, String hexInfoHash) {
if (peers.size() == 0) return;
SharedTorrent torrent = torrentsStorage.getTorrent(hexInfoHash);
if (torrent != null && torrent.isFinished()) return;
final LoadedTorrent announceableTorrent = torrentsStorage.getLoadedTorrent(hexInfoHash);
if (announceableTorrent == null) {
logger.info("announceable torrent {} is not found in storage. Maybe it was removed", hexInfoHash);
return;
}
if (announceableTorrent.getPieceStorage().isFinished()) return;
logger.debug("Got {} peer(s) ({}) for {} in tracker response", new Object[]{peers.size(),
Arrays.toString(peers.toArray()), hexInfoHash});
Map<PeerUID, Peer> uniquePeers = new HashMap<PeerUID, Peer>();
for (Peer peer : peers) {
final PeerUID peerUID = new PeerUID(peer.getAddress(), hexInfoHash);
if (uniquePeers.containsKey(peerUID)) continue;
uniquePeers.put(peerUID, peer);
}
for (Map.Entry<PeerUID, Peer> e : uniquePeers.entrySet()) {
PeerUID peerUID = e.getKey();
Peer peer = e.getValue();
boolean alreadyConnectedToThisPeer = peersStorage.getSharingPeer(peerUID) != null;
if (alreadyConnectedToThisPeer) {
logger.debug("skipping peer {}, because we already connected to this peer", peer);
continue;
}
ConnectionListener connectionListener = new OutgoingConnectionListener(
this,
announceableTorrent.getTorrentHash(),
peer.getIp(),
peer.getPort());
logger.debug("trying to connect to the peer {}", peer);
boolean connectTaskAdded = this.myConnectionManager.offerConnect(
new ConnectTask(peer.getIp(),
peer.getPort(),
connectionListener,
new SystemTimeService().now(),
Constants.DEFAULT_CONNECTION_TIMEOUT_MILLIS), 1, TimeUnit.SECONDS);
if (!connectTaskAdded) {
logger.info("can not connect to peer {}. Unable to add connect task to connection manager", peer);
}
}
} | java | @Override
public void handleDiscoveredPeers(List<Peer> peers, String hexInfoHash) {
if (peers.size() == 0) return;
SharedTorrent torrent = torrentsStorage.getTorrent(hexInfoHash);
if (torrent != null && torrent.isFinished()) return;
final LoadedTorrent announceableTorrent = torrentsStorage.getLoadedTorrent(hexInfoHash);
if (announceableTorrent == null) {
logger.info("announceable torrent {} is not found in storage. Maybe it was removed", hexInfoHash);
return;
}
if (announceableTorrent.getPieceStorage().isFinished()) return;
logger.debug("Got {} peer(s) ({}) for {} in tracker response", new Object[]{peers.size(),
Arrays.toString(peers.toArray()), hexInfoHash});
Map<PeerUID, Peer> uniquePeers = new HashMap<PeerUID, Peer>();
for (Peer peer : peers) {
final PeerUID peerUID = new PeerUID(peer.getAddress(), hexInfoHash);
if (uniquePeers.containsKey(peerUID)) continue;
uniquePeers.put(peerUID, peer);
}
for (Map.Entry<PeerUID, Peer> e : uniquePeers.entrySet()) {
PeerUID peerUID = e.getKey();
Peer peer = e.getValue();
boolean alreadyConnectedToThisPeer = peersStorage.getSharingPeer(peerUID) != null;
if (alreadyConnectedToThisPeer) {
logger.debug("skipping peer {}, because we already connected to this peer", peer);
continue;
}
ConnectionListener connectionListener = new OutgoingConnectionListener(
this,
announceableTorrent.getTorrentHash(),
peer.getIp(),
peer.getPort());
logger.debug("trying to connect to the peer {}", peer);
boolean connectTaskAdded = this.myConnectionManager.offerConnect(
new ConnectTask(peer.getIp(),
peer.getPort(),
connectionListener,
new SystemTimeService().now(),
Constants.DEFAULT_CONNECTION_TIMEOUT_MILLIS), 1, TimeUnit.SECONDS);
if (!connectTaskAdded) {
logger.info("can not connect to peer {}. Unable to add connect task to connection manager", peer);
}
}
} | [
"@",
"Override",
"public",
"void",
"handleDiscoveredPeers",
"(",
"List",
"<",
"Peer",
">",
"peers",
",",
"String",
"hexInfoHash",
")",
"{",
"if",
"(",
"peers",
".",
"size",
"(",
")",
"==",
"0",
")",
"return",
";",
"SharedTorrent",
"torrent",
"=",
"torren... | Handle the discovery of new peers.
@param peers The list of peers discovered (from the announce response or
any other means like DHT/PEX, etc.). | [
"Handle",
"the",
"discovery",
"of",
"new",
"peers",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java#L620-L676 | train |
mpetazzoni/ttorrent | common/src/main/java/com/turn/ttorrent/common/TorrentUtils.java | TorrentUtils.byteArrayToHexString | public static String byteArrayToHexString(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_SYMBOLS[v >>> 4];
hexChars[j * 2 + 1] = HEX_SYMBOLS[v & 0x0F];
}
return new String(hexChars);
} | java | public static String byteArrayToHexString(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_SYMBOLS[v >>> 4];
hexChars[j * 2 + 1] = HEX_SYMBOLS[v & 0x0F];
}
return new String(hexChars);
} | [
"public",
"static",
"String",
"byteArrayToHexString",
"(",
"byte",
"[",
"]",
"bytes",
")",
"{",
"char",
"[",
"]",
"hexChars",
"=",
"new",
"char",
"[",
"bytes",
".",
"length",
"*",
"2",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"b... | Convert a byte string to a string containing an hexadecimal
representation of the original data.
@param bytes The byte array to convert. | [
"Convert",
"a",
"byte",
"string",
"to",
"a",
"string",
"containing",
"an",
"hexadecimal",
"representation",
"of",
"the",
"original",
"data",
"."
] | ecd0e6caf853b63393c4ab63cfd8f20114f73f70 | https://github.com/mpetazzoni/ttorrent/blob/ecd0e6caf853b63393c4ab63cfd8f20114f73f70/common/src/main/java/com/turn/ttorrent/common/TorrentUtils.java#L26-L34 | train |
spring-cloud/spring-cloud-zookeeper | spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java | ZookeeperHealthAutoConfiguration.zookeeperHealthIndicator | @Bean
@ConditionalOnMissingBean(ZookeeperHealthIndicator.class)
@ConditionalOnBean(CuratorFramework.class)
@ConditionalOnEnabledHealthIndicator("zookeeper")
public ZookeeperHealthIndicator zookeeperHealthIndicator(CuratorFramework curator) {
return new ZookeeperHealthIndicator(curator);
} | java | @Bean
@ConditionalOnMissingBean(ZookeeperHealthIndicator.class)
@ConditionalOnBean(CuratorFramework.class)
@ConditionalOnEnabledHealthIndicator("zookeeper")
public ZookeeperHealthIndicator zookeeperHealthIndicator(CuratorFramework curator) {
return new ZookeeperHealthIndicator(curator);
} | [
"@",
"Bean",
"@",
"ConditionalOnMissingBean",
"(",
"ZookeeperHealthIndicator",
".",
"class",
")",
"@",
"ConditionalOnBean",
"(",
"CuratorFramework",
".",
"class",
")",
"@",
"ConditionalOnEnabledHealthIndicator",
"(",
"\"zookeeper\"",
")",
"public",
"ZookeeperHealthIndicat... | If there is an active curator, if the zookeeper health endpoint is enabled and if a
health indicator hasn't already been added by a user add one.
@param curator The curator connection to zookeeper to use
@return An instance of {@link ZookeeperHealthIndicator} to add to actuator health
report | [
"If",
"there",
"is",
"an",
"active",
"curator",
"if",
"the",
"zookeeper",
"health",
"endpoint",
"is",
"enabled",
"and",
"if",
"a",
"health",
"indicator",
"hasn",
"t",
"already",
"been",
"added",
"by",
"a",
"user",
"add",
"one",
"."
] | 1ed80350fe381c4e73fa797741f5ec319db22073 | https://github.com/spring-cloud/spring-cloud-zookeeper/blob/1ed80350fe381c4e73fa797741f5ec319db22073/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java#L50-L56 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/ExplicitMappingBuilder.java | ExplicitMappingBuilder.createProxies | private void createProxies() {
source = createProxy(sourceType);
destination = createProxy(destinationType);
for (VisitedMapping mapping : visitedMappings) {
createAccessorProxies(source, mapping.sourceAccessors);
createAccessorProxies(destination, mapping.destinationAccessors);
}
} | java | private void createProxies() {
source = createProxy(sourceType);
destination = createProxy(destinationType);
for (VisitedMapping mapping : visitedMappings) {
createAccessorProxies(source, mapping.sourceAccessors);
createAccessorProxies(destination, mapping.destinationAccessors);
}
} | [
"private",
"void",
"createProxies",
"(",
")",
"{",
"source",
"=",
"createProxy",
"(",
"sourceType",
")",
";",
"destination",
"=",
"createProxy",
"(",
"destinationType",
")",
";",
"for",
"(",
"VisitedMapping",
"mapping",
":",
"visitedMappings",
")",
"{",
"creat... | Creates the source and destination proxy models. | [
"Creates",
"the",
"source",
"and",
"destination",
"proxy",
"models",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/ExplicitMappingBuilder.java#L272-L280 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/ExplicitMappingBuilder.java | ExplicitMappingBuilder.validateRecordedMapping | private void validateRecordedMapping() {
if (currentMapping.destinationMutators == null || currentMapping.destinationMutators.isEmpty())
errors.missingDestination();
// If mapping a field without a source
else if (options.skipType == 0
&& (currentMapping.sourceAccessors == null || currentMapping.sourceAccessors.isEmpty())
&& currentMapping.destinationMutators.get(currentMapping.destinationMutators.size() - 1)
.getPropertyType()
.equals(PropertyType.FIELD) && options.converter == null && !options.mapFromSource
&& sourceConstant == null)
errors.missingSource();
else if (options.skipType == 2 && options.condition != null)
errors.conditionalSkipWithoutSource();
} | java | private void validateRecordedMapping() {
if (currentMapping.destinationMutators == null || currentMapping.destinationMutators.isEmpty())
errors.missingDestination();
// If mapping a field without a source
else if (options.skipType == 0
&& (currentMapping.sourceAccessors == null || currentMapping.sourceAccessors.isEmpty())
&& currentMapping.destinationMutators.get(currentMapping.destinationMutators.size() - 1)
.getPropertyType()
.equals(PropertyType.FIELD) && options.converter == null && !options.mapFromSource
&& sourceConstant == null)
errors.missingSource();
else if (options.skipType == 2 && options.condition != null)
errors.conditionalSkipWithoutSource();
} | [
"private",
"void",
"validateRecordedMapping",
"(",
")",
"{",
"if",
"(",
"currentMapping",
".",
"destinationMutators",
"==",
"null",
"||",
"currentMapping",
".",
"destinationMutators",
".",
"isEmpty",
"(",
")",
")",
"errors",
".",
"missingDestination",
"(",
")",
... | Validates the current mapping that was recorded via a MapExpression. | [
"Validates",
"the",
"current",
"mapping",
"that",
"was",
"recorded",
"via",
"a",
"MapExpression",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/ExplicitMappingBuilder.java#L347-L360 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/TypeInfoRegistry.java | TypeInfoRegistry.typeInfoFor | @SuppressWarnings("unchecked")
static <T> TypeInfoImpl<T> typeInfoFor(Class<T> sourceType, InheritingConfiguration configuration) {
TypeInfoKey pair = new TypeInfoKey(sourceType, configuration);
TypeInfoImpl<T> typeInfo = (TypeInfoImpl<T>) cache.get(pair);
if (typeInfo == null) {
synchronized (cache) {
typeInfo = (TypeInfoImpl<T>) cache.get(pair);
if (typeInfo == null) {
typeInfo = new TypeInfoImpl<T>(null, sourceType, configuration);
cache.put(pair, typeInfo);
}
}
}
return typeInfo;
} | java | @SuppressWarnings("unchecked")
static <T> TypeInfoImpl<T> typeInfoFor(Class<T> sourceType, InheritingConfiguration configuration) {
TypeInfoKey pair = new TypeInfoKey(sourceType, configuration);
TypeInfoImpl<T> typeInfo = (TypeInfoImpl<T>) cache.get(pair);
if (typeInfo == null) {
synchronized (cache) {
typeInfo = (TypeInfoImpl<T>) cache.get(pair);
if (typeInfo == null) {
typeInfo = new TypeInfoImpl<T>(null, sourceType, configuration);
cache.put(pair, typeInfo);
}
}
}
return typeInfo;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"static",
"<",
"T",
">",
"TypeInfoImpl",
"<",
"T",
">",
"typeInfoFor",
"(",
"Class",
"<",
"T",
">",
"sourceType",
",",
"InheritingConfiguration",
"configuration",
")",
"{",
"TypeInfoKey",
"pair",
"=",
"new",
... | Returns a statically cached TypeInfoImpl instance for the given criteria. | [
"Returns",
"a",
"statically",
"cached",
"TypeInfoImpl",
"instance",
"for",
"the",
"given",
"criteria",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/TypeInfoRegistry.java#L76-L92 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Types.java | Types.mightContainsProperties | public static boolean mightContainsProperties(Class<?> type) {
return type != Object.class
&& type != String.class
&& type != Date.class
&& type != Calendar.class
&& !Primitives.isPrimitive(type)
&& !Iterables.isIterable(type)
&& !Types.isGroovyType(type);
} | java | public static boolean mightContainsProperties(Class<?> type) {
return type != Object.class
&& type != String.class
&& type != Date.class
&& type != Calendar.class
&& !Primitives.isPrimitive(type)
&& !Iterables.isIterable(type)
&& !Types.isGroovyType(type);
} | [
"public",
"static",
"boolean",
"mightContainsProperties",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"return",
"type",
"!=",
"Object",
".",
"class",
"&&",
"type",
"!=",
"String",
".",
"class",
"&&",
"type",
"!=",
"Date",
".",
"class",
"&&",
"type",
... | Returns whether the type might contains properties or not. | [
"Returns",
"whether",
"the",
"type",
"might",
"contains",
"properties",
"or",
"not",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Types.java#L189-L197 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/ImplicitMappingBuilder.java | ImplicitMappingBuilder.mergeMappings | private void mergeMappings(TypeMap<?, ?> destinationMap) {
for (Mapping mapping : destinationMap.getMappings()) {
InternalMapping internalMapping = (InternalMapping) mapping;
mergedMappings.add(internalMapping.createMergedCopy(
propertyNameInfo.getSourceProperties(), propertyNameInfo.getDestinationProperties()));
}
} | java | private void mergeMappings(TypeMap<?, ?> destinationMap) {
for (Mapping mapping : destinationMap.getMappings()) {
InternalMapping internalMapping = (InternalMapping) mapping;
mergedMappings.add(internalMapping.createMergedCopy(
propertyNameInfo.getSourceProperties(), propertyNameInfo.getDestinationProperties()));
}
} | [
"private",
"void",
"mergeMappings",
"(",
"TypeMap",
"<",
"?",
",",
"?",
">",
"destinationMap",
")",
"{",
"for",
"(",
"Mapping",
"mapping",
":",
"destinationMap",
".",
"getMappings",
"(",
")",
")",
"{",
"InternalMapping",
"internalMapping",
"=",
"(",
"Interna... | Merges mappings from an existing TypeMap into the type map under construction. | [
"Merges",
"mappings",
"from",
"an",
"existing",
"TypeMap",
"into",
"the",
"type",
"map",
"under",
"construction",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/ImplicitMappingBuilder.java#L389-L395 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/ImplicitMappingBuilder.java | ImplicitMappingBuilder.isConvertable | private boolean isConvertable(Mapping mapping) {
if (mapping == null || mapping.getProvider() != null || !(mapping instanceof PropertyMapping))
return false;
PropertyMapping propertyMapping = (PropertyMapping) mapping;
boolean hasSupportConverter = converterStore.getFirstSupported(
propertyMapping.getLastSourceProperty().getType(),
mapping.getLastDestinationProperty().getType()) != null;
boolean hasSupportTypeMap = typeMapStore.get(
propertyMapping.getLastSourceProperty().getType(),
mapping.getLastDestinationProperty().getType(),
null) != null;
return hasSupportConverter || hasSupportTypeMap;
} | java | private boolean isConvertable(Mapping mapping) {
if (mapping == null || mapping.getProvider() != null || !(mapping instanceof PropertyMapping))
return false;
PropertyMapping propertyMapping = (PropertyMapping) mapping;
boolean hasSupportConverter = converterStore.getFirstSupported(
propertyMapping.getLastSourceProperty().getType(),
mapping.getLastDestinationProperty().getType()) != null;
boolean hasSupportTypeMap = typeMapStore.get(
propertyMapping.getLastSourceProperty().getType(),
mapping.getLastDestinationProperty().getType(),
null) != null;
return hasSupportConverter || hasSupportTypeMap;
} | [
"private",
"boolean",
"isConvertable",
"(",
"Mapping",
"mapping",
")",
"{",
"if",
"(",
"mapping",
"==",
"null",
"||",
"mapping",
".",
"getProvider",
"(",
")",
"!=",
"null",
"||",
"!",
"(",
"mapping",
"instanceof",
"PropertyMapping",
")",
")",
"return",
"fa... | Indicates whether the mapping represents a PropertyMapping that is convertible to the
destination type. | [
"Indicates",
"whether",
"the",
"mapping",
"represents",
"a",
"PropertyMapping",
"that",
"is",
"convertible",
"to",
"the",
"destination",
"type",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/ImplicitMappingBuilder.java#L402-L416 | train |
modelmapper/modelmapper | examples/src/main/java/org/modelmapper/gettingstarted/GettingStartedExample.java | GettingStartedExample.mapAutomatically | static void mapAutomatically() {
Order order = createOrder();
ModelMapper modelMapper = new ModelMapper();
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
assertOrdersEqual(order, orderDTO);
} | java | static void mapAutomatically() {
Order order = createOrder();
ModelMapper modelMapper = new ModelMapper();
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
assertOrdersEqual(order, orderDTO);
} | [
"static",
"void",
"mapAutomatically",
"(",
")",
"{",
"Order",
"order",
"=",
"createOrder",
"(",
")",
";",
"ModelMapper",
"modelMapper",
"=",
"new",
"ModelMapper",
"(",
")",
";",
"OrderDTO",
"orderDTO",
"=",
"modelMapper",
".",
"map",
"(",
"order",
",",
"Or... | This example demonstrates how ModelMapper automatically maps properties from Order to OrderDTO. | [
"This",
"example",
"demonstrates",
"how",
"ModelMapper",
"automatically",
"maps",
"properties",
"from",
"Order",
"to",
"OrderDTO",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/examples/src/main/java/org/modelmapper/gettingstarted/GettingStartedExample.java#L20-L25 | train |
modelmapper/modelmapper | examples/src/main/java/org/modelmapper/gettingstarted/GettingStartedExample.java | GettingStartedExample.mapExplicitly | static void mapExplicitly() {
Order order = createOrder();
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
@Override
protected void configure() {
map().setBillingStreet(source.getBillingAddress().getStreet());
map(source.billingAddress.getCity(), destination.billingCity);
}
});
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
assertOrdersEqual(order, orderDTO);
} | java | static void mapExplicitly() {
Order order = createOrder();
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
@Override
protected void configure() {
map().setBillingStreet(source.getBillingAddress().getStreet());
map(source.billingAddress.getCity(), destination.billingCity);
}
});
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
assertOrdersEqual(order, orderDTO);
} | [
"static",
"void",
"mapExplicitly",
"(",
")",
"{",
"Order",
"order",
"=",
"createOrder",
"(",
")",
";",
"ModelMapper",
"modelMapper",
"=",
"new",
"ModelMapper",
"(",
")",
";",
"modelMapper",
".",
"addMappings",
"(",
"new",
"PropertyMap",
"<",
"Order",
",",
... | This example demonstrates how ModelMapper can be used to explicitly map properties from an
Order to OrderDTO. | [
"This",
"example",
"demonstrates",
"how",
"ModelMapper",
"can",
"be",
"used",
"to",
"explicitly",
"map",
"properties",
"from",
"an",
"Order",
"to",
"OrderDTO",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/examples/src/main/java/org/modelmapper/gettingstarted/GettingStartedExample.java#L31-L44 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/MappingContextHelper.java | MappingContextHelper.createCollection | public static <T> Collection<T> createCollection(MappingContext<?, Collection<T>> context) {
if (context.getDestinationType().isInterface())
if (SortedSet.class.isAssignableFrom(context.getDestinationType()))
return new TreeSet<T>();
else if (Set.class.isAssignableFrom(context.getDestinationType()))
return new HashSet<T>();
else
return new ArrayList<T>();
return context.getMappingEngine().createDestination(context);
} | java | public static <T> Collection<T> createCollection(MappingContext<?, Collection<T>> context) {
if (context.getDestinationType().isInterface())
if (SortedSet.class.isAssignableFrom(context.getDestinationType()))
return new TreeSet<T>();
else if (Set.class.isAssignableFrom(context.getDestinationType()))
return new HashSet<T>();
else
return new ArrayList<T>();
return context.getMappingEngine().createDestination(context);
} | [
"public",
"static",
"<",
"T",
">",
"Collection",
"<",
"T",
">",
"createCollection",
"(",
"MappingContext",
"<",
"?",
",",
"Collection",
"<",
"T",
">",
">",
"context",
")",
"{",
"if",
"(",
"context",
".",
"getDestinationType",
"(",
")",
".",
"isInterface"... | Creates a collection based on the destination type.
<ul>
<li>Creates {@code TreeSet} for {@code SortedSet}</li>
<li>Creates {@code HashSet} for {@code Set}</li>
<li>Creates {@code ArrayList} for {@code List}</li>
</ul>
@param context the mapping context
@param <T> the element type of the collection
@return an empty collection | [
"Creates",
"a",
"collection",
"based",
"on",
"the",
"destination",
"type",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/MappingContextHelper.java#L38-L47 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/Errors.java | Errors.format | public static String format(String heading, Collection<ErrorMessage> errorMessages) {
@SuppressWarnings("resource")
Formatter fmt = new Formatter().format(heading).format(":%n%n");
int index = 1;
boolean displayCauses = getOnlyCause(errorMessages) == null;
for (ErrorMessage errorMessage : errorMessages) {
fmt.format("%s) %s%n", index++, errorMessage.getMessage());
Throwable cause = errorMessage.getCause();
if (displayCauses && cause != null) {
StringWriter writer = new StringWriter();
cause.printStackTrace(new PrintWriter(writer));
fmt.format("Caused by: %s", writer.getBuffer());
}
fmt.format("%n");
}
if (errorMessages.size() == 1)
fmt.format("1 error");
else
fmt.format("%s errors", errorMessages.size());
return fmt.toString();
} | java | public static String format(String heading, Collection<ErrorMessage> errorMessages) {
@SuppressWarnings("resource")
Formatter fmt = new Formatter().format(heading).format(":%n%n");
int index = 1;
boolean displayCauses = getOnlyCause(errorMessages) == null;
for (ErrorMessage errorMessage : errorMessages) {
fmt.format("%s) %s%n", index++, errorMessage.getMessage());
Throwable cause = errorMessage.getCause();
if (displayCauses && cause != null) {
StringWriter writer = new StringWriter();
cause.printStackTrace(new PrintWriter(writer));
fmt.format("Caused by: %s", writer.getBuffer());
}
fmt.format("%n");
}
if (errorMessages.size() == 1)
fmt.format("1 error");
else
fmt.format("%s errors", errorMessages.size());
return fmt.toString();
} | [
"public",
"static",
"String",
"format",
"(",
"String",
"heading",
",",
"Collection",
"<",
"ErrorMessage",
">",
"errorMessages",
")",
"{",
"@",
"SuppressWarnings",
"(",
"\"resource\"",
")",
"Formatter",
"fmt",
"=",
"new",
"Formatter",
"(",
")",
".",
"format",
... | Returns the formatted message for an exception with the specified messages. | [
"Returns",
"the",
"formatted",
"message",
"for",
"an",
"exception",
"with",
"the",
"specified",
"messages",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/Errors.java#L93-L118 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/TypeInfoImpl.java | TypeInfoImpl.getAccessors | public Map<String, Accessor> getAccessors() {
if (accessors == null)
synchronized (this) {
if (accessors == null)
accessors = PropertyInfoSetResolver.resolveAccessors(source, type, configuration);
}
return accessors;
} | java | public Map<String, Accessor> getAccessors() {
if (accessors == null)
synchronized (this) {
if (accessors == null)
accessors = PropertyInfoSetResolver.resolveAccessors(source, type, configuration);
}
return accessors;
} | [
"public",
"Map",
"<",
"String",
",",
"Accessor",
">",
"getAccessors",
"(",
")",
"{",
"if",
"(",
"accessors",
"==",
"null",
")",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"accessors",
"==",
"null",
")",
"accessors",
"=",
"PropertyInfoSetResolver",
... | Lazily initializes and gets accessors. | [
"Lazily",
"initializes",
"and",
"gets",
"accessors",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/TypeInfoImpl.java#L55-L63 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/TypeInfoImpl.java | TypeInfoImpl.getMutators | public Map<String, Mutator> getMutators() {
if (mutators == null)
synchronized (this) {
if (mutators == null)
mutators = PropertyInfoSetResolver.resolveMutators(type, configuration);
}
return mutators;
} | java | public Map<String, Mutator> getMutators() {
if (mutators == null)
synchronized (this) {
if (mutators == null)
mutators = PropertyInfoSetResolver.resolveMutators(type, configuration);
}
return mutators;
} | [
"public",
"Map",
"<",
"String",
",",
"Mutator",
">",
"getMutators",
"(",
")",
"{",
"if",
"(",
"mutators",
"==",
"null",
")",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"mutators",
"==",
"null",
")",
"mutators",
"=",
"PropertyInfoSetResolver",
".",... | Lazily initializes and gets mutators. | [
"Lazily",
"initializes",
"and",
"gets",
"mutators",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/TypeInfoImpl.java#L72-L80 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java | PropertyInfoRegistry.accessorFor | static synchronized Accessor accessorFor(Class<?> type, Method method,
Configuration configuration, String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
Accessor accessor = ACCESSOR_CACHE.get(key);
if (accessor == null) {
accessor = new MethodAccessor(type, method, name);
ACCESSOR_CACHE.put(key, accessor);
}
return accessor;
} | java | static synchronized Accessor accessorFor(Class<?> type, Method method,
Configuration configuration, String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
Accessor accessor = ACCESSOR_CACHE.get(key);
if (accessor == null) {
accessor = new MethodAccessor(type, method, name);
ACCESSOR_CACHE.put(key, accessor);
}
return accessor;
} | [
"static",
"synchronized",
"Accessor",
"accessorFor",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Method",
"method",
",",
"Configuration",
"configuration",
",",
"String",
"name",
")",
"{",
"PropertyInfoKey",
"key",
"=",
"new",
"PropertyInfoKey",
"(",
"type",
","... | Returns an Accessor for the given accessor method. The method must be externally validated to
ensure that it accepts zero arguments and does not return void.class. | [
"Returns",
"an",
"Accessor",
"for",
"the",
"given",
"accessor",
"method",
".",
"The",
"method",
"must",
"be",
"externally",
"validated",
"to",
"ensure",
"that",
"it",
"accepts",
"zero",
"arguments",
"and",
"does",
"not",
"return",
"void",
".",
"class",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java#L98-L108 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java | PropertyInfoRegistry.fieldPropertyFor | static synchronized FieldPropertyInfo fieldPropertyFor(Class<?> type, Field field,
Configuration configuration, String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
FieldPropertyInfo fieldPropertyInfo = FIELD_CACHE.get(key);
if (fieldPropertyInfo == null) {
fieldPropertyInfo = new FieldPropertyInfo(type, field, name);
FIELD_CACHE.put(key, fieldPropertyInfo);
}
return fieldPropertyInfo;
} | java | static synchronized FieldPropertyInfo fieldPropertyFor(Class<?> type, Field field,
Configuration configuration, String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
FieldPropertyInfo fieldPropertyInfo = FIELD_CACHE.get(key);
if (fieldPropertyInfo == null) {
fieldPropertyInfo = new FieldPropertyInfo(type, field, name);
FIELD_CACHE.put(key, fieldPropertyInfo);
}
return fieldPropertyInfo;
} | [
"static",
"synchronized",
"FieldPropertyInfo",
"fieldPropertyFor",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Field",
"field",
",",
"Configuration",
"configuration",
",",
"String",
"name",
")",
"{",
"PropertyInfoKey",
"key",
"=",
"new",
"PropertyInfoKey",
"(",
"... | Returns a FieldPropertyInfo instance for the given field. | [
"Returns",
"a",
"FieldPropertyInfo",
"instance",
"for",
"the",
"given",
"field",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java#L113-L123 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java | PropertyInfoRegistry.mutatorFor | static synchronized Mutator mutatorFor(Class<?> type, Method method, Configuration configuration,
String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
Mutator mutator = MUTATOR_CACHE.get(key);
if (mutator == null) {
mutator = new MethodMutator(type, method, name);
MUTATOR_CACHE.put(key, mutator);
}
return mutator;
} | java | static synchronized Mutator mutatorFor(Class<?> type, Method method, Configuration configuration,
String name) {
PropertyInfoKey key = new PropertyInfoKey(type, name, configuration);
Mutator mutator = MUTATOR_CACHE.get(key);
if (mutator == null) {
mutator = new MethodMutator(type, method, name);
MUTATOR_CACHE.put(key, mutator);
}
return mutator;
} | [
"static",
"synchronized",
"Mutator",
"mutatorFor",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Method",
"method",
",",
"Configuration",
"configuration",
",",
"String",
"name",
")",
"{",
"PropertyInfoKey",
"key",
"=",
"new",
"PropertyInfoKey",
"(",
"type",
",",
... | Returns a Mutator instance for the given mutator method. The method must be externally
validated to ensure that it accepts one argument and returns void.class. | [
"Returns",
"a",
"Mutator",
"instance",
"for",
"the",
"given",
"mutator",
"method",
".",
"The",
"method",
"must",
"be",
"externally",
"validated",
"to",
"ensure",
"that",
"it",
"accepts",
"one",
"argument",
"and",
"returns",
"void",
".",
"class",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/PropertyInfoRegistry.java#L152-L162 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Iterables.java | Iterables.getLength | @SuppressWarnings("unchecked")
public static int getLength(Object iterable) {
Assert.state(isIterable(iterable.getClass()));
return iterable.getClass().isArray() ? Array.getLength(iterable) : ((Collection<Object>) iterable).size();
} | java | @SuppressWarnings("unchecked")
public static int getLength(Object iterable) {
Assert.state(isIterable(iterable.getClass()));
return iterable.getClass().isArray() ? Array.getLength(iterable) : ((Collection<Object>) iterable).size();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"int",
"getLength",
"(",
"Object",
"iterable",
")",
"{",
"Assert",
".",
"state",
"(",
"isIterable",
"(",
"iterable",
".",
"getClass",
"(",
")",
")",
")",
";",
"return",
"iterable",
"."... | Gets the length of an iterable.
@param iterable the iterable
@return the length of the iterable | [
"Gets",
"the",
"length",
"of",
"an",
"iterable",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Iterables.java#L47-L51 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Iterables.java | Iterables.iterator | @SuppressWarnings("unchecked")
public static Iterator<Object> iterator(Object iterable) {
Assert.state(isIterable(iterable.getClass()));
return iterable.getClass().isArray() ? new ArrayIterator(iterable)
: ((Iterable<Object>) iterable).iterator();
} | java | @SuppressWarnings("unchecked")
public static Iterator<Object> iterator(Object iterable) {
Assert.state(isIterable(iterable.getClass()));
return iterable.getClass().isArray() ? new ArrayIterator(iterable)
: ((Iterable<Object>) iterable).iterator();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"Iterator",
"<",
"Object",
">",
"iterator",
"(",
"Object",
"iterable",
")",
"{",
"Assert",
".",
"state",
"(",
"isIterable",
"(",
"iterable",
".",
"getClass",
"(",
")",
")",
")",
";",
... | Creates a iterator from given iterable.
@param iterable the iterable
@return a iterator | [
"Creates",
"a",
"iterator",
"from",
"given",
"iterable",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Iterables.java#L59-L64 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Iterables.java | Iterables.getElement | @SuppressWarnings("unchecked")
public static Object getElement(Object iterable, int index) {
if (iterable.getClass().isArray())
return getElementFromArrary(iterable, index);
if (iterable instanceof Collection)
return getElementFromCollection((Collection<Object>) iterable, index);
return null;
} | java | @SuppressWarnings("unchecked")
public static Object getElement(Object iterable, int index) {
if (iterable.getClass().isArray())
return getElementFromArrary(iterable, index);
if (iterable instanceof Collection)
return getElementFromCollection((Collection<Object>) iterable, index);
return null;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"Object",
"getElement",
"(",
"Object",
"iterable",
",",
"int",
"index",
")",
"{",
"if",
"(",
"iterable",
".",
"getClass",
"(",
")",
".",
"isArray",
"(",
")",
")",
"return",
"getElement... | Gets the element from an iterable with given index.
@param iterable the iterable
@param index the index
@return null if the iterable doesn't have the element at index, otherwise, return the element | [
"Gets",
"the",
"element",
"from",
"an",
"iterable",
"with",
"given",
"index",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Iterables.java#L73-L81 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Iterables.java | Iterables.getElementFromArrary | public static Object getElementFromArrary(Object array, int index) {
try {
return Array.get(array, index);
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
} | java | public static Object getElementFromArrary(Object array, int index) {
try {
return Array.get(array, index);
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
} | [
"public",
"static",
"Object",
"getElementFromArrary",
"(",
"Object",
"array",
",",
"int",
"index",
")",
"{",
"try",
"{",
"return",
"Array",
".",
"get",
"(",
"array",
",",
"index",
")",
";",
"}",
"catch",
"(",
"ArrayIndexOutOfBoundsException",
"e",
")",
"{"... | Gets the element from an array with given index.
@param array the array
@param index the index
@return null if the array doesn't have the element at index, otherwise, return the element | [
"Gets",
"the",
"element",
"from",
"an",
"array",
"with",
"given",
"index",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Iterables.java#L90-L96 | train |
modelmapper/modelmapper | core/src/main/java/org/modelmapper/internal/util/Iterables.java | Iterables.getElementFromCollection | public static Object getElementFromCollection(Collection<Object> collection, int index) {
if (collection.size() < index + 1)
return null;
if (collection instanceof List)
return ((List<Object>) collection).get(index);
Iterator<Object> iterator = collection.iterator();
for (int i = 0; i < index; i++) {
iterator.next();
}
return iterator.next();
} | java | public static Object getElementFromCollection(Collection<Object> collection, int index) {
if (collection.size() < index + 1)
return null;
if (collection instanceof List)
return ((List<Object>) collection).get(index);
Iterator<Object> iterator = collection.iterator();
for (int i = 0; i < index; i++) {
iterator.next();
}
return iterator.next();
} | [
"public",
"static",
"Object",
"getElementFromCollection",
"(",
"Collection",
"<",
"Object",
">",
"collection",
",",
"int",
"index",
")",
"{",
"if",
"(",
"collection",
".",
"size",
"(",
")",
"<",
"index",
"+",
"1",
")",
"return",
"null",
";",
"if",
"(",
... | Gets the element from a collection with given index.
@param collection the collection
@param index the index
@return null if the collection doesn't have the element at index, otherwise, return the element | [
"Gets",
"the",
"element",
"from",
"a",
"collection",
"with",
"given",
"index",
"."
] | 491d165ded9dc9aba7ce8b56984249e1a1363204 | https://github.com/modelmapper/modelmapper/blob/491d165ded9dc9aba7ce8b56984249e1a1363204/core/src/main/java/org/modelmapper/internal/util/Iterables.java#L105-L117 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/FFcommon.java | FFcommon.version | public synchronized @Nonnull String version() throws IOException {
if (this.version == null) {
Process p = runFunc.run(ImmutableList.of(path, "-version"));
try {
BufferedReader r = wrapInReader(p);
this.version = r.readLine();
CharStreams.copy(r, CharStreams.nullWriter()); // Throw away rest of the output
throwOnError(p);
} finally {
p.destroy();
}
}
return version;
} | java | public synchronized @Nonnull String version() throws IOException {
if (this.version == null) {
Process p = runFunc.run(ImmutableList.of(path, "-version"));
try {
BufferedReader r = wrapInReader(p);
this.version = r.readLine();
CharStreams.copy(r, CharStreams.nullWriter()); // Throw away rest of the output
throwOnError(p);
} finally {
p.destroy();
}
}
return version;
} | [
"public",
"synchronized",
"@",
"Nonnull",
"String",
"version",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"this",
".",
"version",
"==",
"null",
")",
"{",
"Process",
"p",
"=",
"runFunc",
".",
"run",
"(",
"ImmutableList",
".",
"of",
"(",
"path",
... | Returns the version string for this binary.
@return the version string.
@throws IOException If there is an error capturing output from the binary. | [
"Returns",
"the",
"version",
"string",
"for",
"this",
"binary",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/FFcommon.java#L64-L78 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/FFcommon.java | FFcommon.path | public List<String> path(List<String> args) throws IOException {
return ImmutableList.<String>builder().add(path).addAll(args).build();
} | java | public List<String> path(List<String> args) throws IOException {
return ImmutableList.<String>builder().add(path).addAll(args).build();
} | [
"public",
"List",
"<",
"String",
">",
"path",
"(",
"List",
"<",
"String",
">",
"args",
")",
"throws",
"IOException",
"{",
"return",
"ImmutableList",
".",
"<",
"String",
">",
"builder",
"(",
")",
".",
"add",
"(",
"path",
")",
".",
"addAll",
"(",
"args... | Returns the full path to the binary with arguments appended.
@param args The arguments to pass to the binary.
@return The full path and arguments to execute the binary.
@throws IOException If there is an error capturing output from the binary | [
"Returns",
"the",
"full",
"path",
"to",
"the",
"binary",
"with",
"arguments",
"appended",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/FFcommon.java#L91-L93 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/Preconditions.java | Preconditions.checkValidStream | public static URI checkValidStream(URI uri) throws IllegalArgumentException {
String scheme = checkNotNull(uri).getScheme();
scheme = checkNotNull(scheme, "URI is missing a scheme").toLowerCase();
if (rtps.contains(scheme)) {
return uri;
}
if (udpTcp.contains(scheme)) {
if (uri.getPort() == -1) {
throw new IllegalArgumentException("must set port when using udp or tcp scheme");
}
return uri;
}
throw new IllegalArgumentException("not a valid output URL, must use rtp/tcp/udp scheme");
} | java | public static URI checkValidStream(URI uri) throws IllegalArgumentException {
String scheme = checkNotNull(uri).getScheme();
scheme = checkNotNull(scheme, "URI is missing a scheme").toLowerCase();
if (rtps.contains(scheme)) {
return uri;
}
if (udpTcp.contains(scheme)) {
if (uri.getPort() == -1) {
throw new IllegalArgumentException("must set port when using udp or tcp scheme");
}
return uri;
}
throw new IllegalArgumentException("not a valid output URL, must use rtp/tcp/udp scheme");
} | [
"public",
"static",
"URI",
"checkValidStream",
"(",
"URI",
"uri",
")",
"throws",
"IllegalArgumentException",
"{",
"String",
"scheme",
"=",
"checkNotNull",
"(",
"uri",
")",
".",
"getScheme",
"(",
")",
";",
"scheme",
"=",
"checkNotNull",
"(",
"scheme",
",",
"\... | Checks if the URI is valid for streaming to.
@param uri The URI to check
@return The passed in URI if it is valid
@throws IllegalArgumentException if the URI is not valid. | [
"Checks",
"if",
"the",
"URI",
"is",
"valid",
"for",
"streaming",
"to",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/Preconditions.java#L43-L59 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/PacketHeader.java | PacketHeader.read | public void read(NutDataInputStream in, long startcode) throws IOException {
this.startcode = startcode;
forwardPtr = in.readVarLong();
if (forwardPtr > 4096) {
long expected = in.getCRC();
checksum = in.readInt();
if (checksum != expected) {
// TODO This code path has never been tested.
throw new IOException(
String.format("invalid header checksum %X want %X", expected, checksum));
}
}
in.resetCRC();
end = in.offset() + forwardPtr - 4; // 4 bytes for footer CRC
} | java | public void read(NutDataInputStream in, long startcode) throws IOException {
this.startcode = startcode;
forwardPtr = in.readVarLong();
if (forwardPtr > 4096) {
long expected = in.getCRC();
checksum = in.readInt();
if (checksum != expected) {
// TODO This code path has never been tested.
throw new IOException(
String.format("invalid header checksum %X want %X", expected, checksum));
}
}
in.resetCRC();
end = in.offset() + forwardPtr - 4; // 4 bytes for footer CRC
} | [
"public",
"void",
"read",
"(",
"NutDataInputStream",
"in",
",",
"long",
"startcode",
")",
"throws",
"IOException",
"{",
"this",
".",
"startcode",
"=",
"startcode",
";",
"forwardPtr",
"=",
"in",
".",
"readVarLong",
"(",
")",
";",
"if",
"(",
"forwardPtr",
">... | End byte of packet | [
"End",
"byte",
"of",
"packet"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/PacketHeader.java#L15-L30 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/FFmpegOutputBuilder.java | FFmpegOutputBuilder.buildOptions | @CheckReturnValue
@Override
public EncodingOptions buildOptions() {
// TODO When/if modelmapper supports @ConstructorProperties, we map this
// object, instead of doing new XXX(...)
// https://github.com/jhalterman/modelmapper/issues/44
return new EncodingOptions(
new MainEncodingOptions(format, startOffset, duration),
new AudioEncodingOptions(
audio_enabled,
audio_codec,
audio_channels,
audio_sample_rate,
audio_sample_format,
audio_bit_rate,
audio_quality),
new VideoEncodingOptions(
video_enabled,
video_codec,
video_frame_rate,
video_width,
video_height,
video_bit_rate,
video_frames,
video_filter,
video_preset));
} | java | @CheckReturnValue
@Override
public EncodingOptions buildOptions() {
// TODO When/if modelmapper supports @ConstructorProperties, we map this
// object, instead of doing new XXX(...)
// https://github.com/jhalterman/modelmapper/issues/44
return new EncodingOptions(
new MainEncodingOptions(format, startOffset, duration),
new AudioEncodingOptions(
audio_enabled,
audio_codec,
audio_channels,
audio_sample_rate,
audio_sample_format,
audio_bit_rate,
audio_quality),
new VideoEncodingOptions(
video_enabled,
video_codec,
video_frame_rate,
video_width,
video_height,
video_bit_rate,
video_frames,
video_filter,
video_preset));
} | [
"@",
"CheckReturnValue",
"@",
"Override",
"public",
"EncodingOptions",
"buildOptions",
"(",
")",
"{",
"// TODO When/if modelmapper supports @ConstructorProperties, we map this",
"// object, instead of doing new XXX(...)",
"// https://github.com/jhalterman/modelmapper/issues/44",
"return",
... | Returns a representation of this Builder that can be safely serialised.
<p>NOTE: This method is horribly out of date, and its use should be rethought.
@return A new EncodingOptions capturing this Builder's state | [
"Returns",
"a",
"representation",
"of",
"this",
"Builder",
"that",
"can",
"be",
"safely",
"serialised",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/FFmpegOutputBuilder.java#L186-L212 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutReader.java | NutReader.readFileId | protected void readFileId() throws IOException {
byte[] b = new byte[HEADER.length];
in.readFully(b);
if (!Arrays.equals(b, HEADER)) {
throw new IOException(
"file_id_string does not match. got: " + new String(b, Charsets.ISO_8859_1));
}
} | java | protected void readFileId() throws IOException {
byte[] b = new byte[HEADER.length];
in.readFully(b);
if (!Arrays.equals(b, HEADER)) {
throw new IOException(
"file_id_string does not match. got: " + new String(b, Charsets.ISO_8859_1));
}
} | [
"protected",
"void",
"readFileId",
"(",
")",
"throws",
"IOException",
"{",
"byte",
"[",
"]",
"b",
"=",
"new",
"byte",
"[",
"HEADER",
".",
"length",
"]",
";",
"in",
".",
"readFully",
"(",
"b",
")",
";",
"if",
"(",
"!",
"Arrays",
".",
"equals",
"(",
... | Read the magic at the beginning of the file.
@throws IOException If a I/O error occurs | [
"Read",
"the",
"magic",
"at",
"the",
"beginning",
"of",
"the",
"file",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutReader.java#L52-L60 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutReader.java | NutReader.readReservedHeaders | protected long readReservedHeaders() throws IOException {
long startcode = in.readStartCode();
while (Startcode.isPossibleStartcode(startcode) && isKnownStartcode(startcode)) {
new Packet().read(in, startcode); // Discard unknown packet
startcode = in.readStartCode();
}
return startcode;
} | java | protected long readReservedHeaders() throws IOException {
long startcode = in.readStartCode();
while (Startcode.isPossibleStartcode(startcode) && isKnownStartcode(startcode)) {
new Packet().read(in, startcode); // Discard unknown packet
startcode = in.readStartCode();
}
return startcode;
} | [
"protected",
"long",
"readReservedHeaders",
"(",
")",
"throws",
"IOException",
"{",
"long",
"startcode",
"=",
"in",
".",
"readStartCode",
"(",
")",
";",
"while",
"(",
"Startcode",
".",
"isPossibleStartcode",
"(",
"startcode",
")",
"&&",
"isKnownStartcode",
"(",
... | Read headers we don't know how to parse yet, returning the next startcode.
@return The next startcode
@throws IOException If a I/O error occurs | [
"Read",
"headers",
"we",
"don",
"t",
"know",
"how",
"to",
"parse",
"yet",
"returning",
"the",
"next",
"startcode",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutReader.java#L68-L76 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutReader.java | NutReader.read | public void read() throws IOException {
readFileId();
in.resetCRC();
long startcode = in.readStartCode();
while (true) {
// Start parsing main and stream information
header = new MainHeaderPacket();
if (!Startcode.MAIN.equalsCode(startcode)) {
throw new IOException(String.format("expected main header found: 0x%X", startcode));
}
header.read(in, startcode);
startcode = readReservedHeaders();
streams.clear();
for (int i = 0; i < header.streamCount; i++) {
if (!Startcode.STREAM.equalsCode(startcode)) {
throw new IOException(String.format("expected stream header found: 0x%X", startcode));
}
StreamHeaderPacket streamHeader = new StreamHeaderPacket();
streamHeader.read(in, startcode);
Stream stream = new Stream(header, streamHeader);
streams.add(stream);
listener.stream(stream);
startcode = readReservedHeaders();
}
while (Startcode.INFO.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = readReservedHeaders();
}
if (Startcode.INDEX.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = in.readStartCode();
}
// Now main frame parsing loop
while (!Startcode.MAIN.equalsCode(startcode)) {
if (Startcode.SYNCPOINT.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = in.readStartCode();
}
if (Startcode.isPossibleStartcode(startcode)) {
throw new IOException("expected framecode, found " + Startcode.toString(startcode));
}
Frame f = new Frame();
f.read(this, in, (int) startcode);
listener.frame(f);
try {
startcode = readReservedHeaders();
} catch (java.io.EOFException e) {
return;
}
}
}
} | java | public void read() throws IOException {
readFileId();
in.resetCRC();
long startcode = in.readStartCode();
while (true) {
// Start parsing main and stream information
header = new MainHeaderPacket();
if (!Startcode.MAIN.equalsCode(startcode)) {
throw new IOException(String.format("expected main header found: 0x%X", startcode));
}
header.read(in, startcode);
startcode = readReservedHeaders();
streams.clear();
for (int i = 0; i < header.streamCount; i++) {
if (!Startcode.STREAM.equalsCode(startcode)) {
throw new IOException(String.format("expected stream header found: 0x%X", startcode));
}
StreamHeaderPacket streamHeader = new StreamHeaderPacket();
streamHeader.read(in, startcode);
Stream stream = new Stream(header, streamHeader);
streams.add(stream);
listener.stream(stream);
startcode = readReservedHeaders();
}
while (Startcode.INFO.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = readReservedHeaders();
}
if (Startcode.INDEX.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = in.readStartCode();
}
// Now main frame parsing loop
while (!Startcode.MAIN.equalsCode(startcode)) {
if (Startcode.SYNCPOINT.equalsCode(startcode)) {
new Packet().read(in, startcode); // Discard for the moment
startcode = in.readStartCode();
}
if (Startcode.isPossibleStartcode(startcode)) {
throw new IOException("expected framecode, found " + Startcode.toString(startcode));
}
Frame f = new Frame();
f.read(this, in, (int) startcode);
listener.frame(f);
try {
startcode = readReservedHeaders();
} catch (java.io.EOFException e) {
return;
}
}
}
} | [
"public",
"void",
"read",
"(",
")",
"throws",
"IOException",
"{",
"readFileId",
"(",
")",
";",
"in",
".",
"resetCRC",
"(",
")",
";",
"long",
"startcode",
"=",
"in",
".",
"readStartCode",
"(",
")",
";",
"while",
"(",
"true",
")",
"{",
"// Start parsing ... | Demux the inputstream
@throws IOException If a I/O error occurs | [
"Demux",
"the",
"inputstream"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutReader.java#L83-L150 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setVideoFrameRate | public T setVideoFrameRate(Fraction frame_rate) {
this.video_enabled = true;
this.video_frame_rate = checkNotNull(frame_rate);
return getThis();
} | java | public T setVideoFrameRate(Fraction frame_rate) {
this.video_enabled = true;
this.video_frame_rate = checkNotNull(frame_rate);
return getThis();
} | [
"public",
"T",
"setVideoFrameRate",
"(",
"Fraction",
"frame_rate",
")",
"{",
"this",
".",
"video_enabled",
"=",
"true",
";",
"this",
".",
"video_frame_rate",
"=",
"checkNotNull",
"(",
"frame_rate",
")",
";",
"return",
"getThis",
"(",
")",
";",
"}"
] | Sets the video's frame rate
@param frame_rate Frames per second
@return this
@see net.bramp.ffmpeg.FFmpeg#FPS_30
@see net.bramp.ffmpeg.FFmpeg#FPS_29_97
@see net.bramp.ffmpeg.FFmpeg#FPS_24
@see net.bramp.ffmpeg.FFmpeg#FPS_23_976 | [
"Sets",
"the",
"video",
"s",
"frame",
"rate"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L237-L241 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.addMetaTag | public T addMetaTag(String key, String value) {
checkValidKey(key);
checkNotEmpty(value, "value must not be empty");
meta_tags.add("-metadata");
meta_tags.add(key + "=" + value);
return getThis();
} | java | public T addMetaTag(String key, String value) {
checkValidKey(key);
checkNotEmpty(value, "value must not be empty");
meta_tags.add("-metadata");
meta_tags.add(key + "=" + value);
return getThis();
} | [
"public",
"T",
"addMetaTag",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"checkValidKey",
"(",
"key",
")",
";",
"checkNotEmpty",
"(",
"value",
",",
"\"value must not be empty\"",
")",
";",
"meta_tags",
".",
"add",
"(",
"\"-metadata\"",
")",
";",
... | Add metadata on output streams. Which keys are possible depends on the used codec.
@param key Metadata key, e.g. "comment"
@param value Value to set for key
@return this | [
"Add",
"metadata",
"on",
"output",
"streams",
".",
"Which",
"keys",
"are",
"possible",
"depends",
"on",
"the",
"used",
"codec",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L329-L335 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setAudioChannels | public T setAudioChannels(int channels) {
checkArgument(channels > 0, "channels must be positive");
this.audio_enabled = true;
this.audio_channels = channels;
return getThis();
} | java | public T setAudioChannels(int channels) {
checkArgument(channels > 0, "channels must be positive");
this.audio_enabled = true;
this.audio_channels = channels;
return getThis();
} | [
"public",
"T",
"setAudioChannels",
"(",
"int",
"channels",
")",
"{",
"checkArgument",
"(",
"channels",
">",
"0",
",",
"\"channels must be positive\"",
")",
";",
"this",
".",
"audio_enabled",
"=",
"true",
";",
"this",
".",
"audio_channels",
"=",
"channels",
";"... | Sets the number of audio channels
@param channels Number of channels
@return this
@see net.bramp.ffmpeg.FFmpeg#AUDIO_MONO
@see net.bramp.ffmpeg.FFmpeg#AUDIO_STEREO | [
"Sets",
"the",
"number",
"of",
"audio",
"channels"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L384-L389 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setAudioSampleRate | public T setAudioSampleRate(int sample_rate) {
checkArgument(sample_rate > 0, "sample rate must be positive");
this.audio_enabled = true;
this.audio_sample_rate = sample_rate;
return getThis();
} | java | public T setAudioSampleRate(int sample_rate) {
checkArgument(sample_rate > 0, "sample rate must be positive");
this.audio_enabled = true;
this.audio_sample_rate = sample_rate;
return getThis();
} | [
"public",
"T",
"setAudioSampleRate",
"(",
"int",
"sample_rate",
")",
"{",
"checkArgument",
"(",
"sample_rate",
">",
"0",
",",
"\"sample rate must be positive\"",
")",
";",
"this",
".",
"audio_enabled",
"=",
"true",
";",
"this",
".",
"audio_sample_rate",
"=",
"sa... | Sets the Audio sample rate, for example 44_000.
@param sample_rate Samples measured in Hz
@return this
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_8000
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_11025
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_12000
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_16000
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_22050
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_32000
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_44100
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_48000
@see net.bramp.ffmpeg.FFmpeg#AUDIO_SAMPLE_96000 | [
"Sets",
"the",
"Audio",
"sample",
"rate",
"for",
"example",
"44_000",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L406-L411 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setStartOffset | public T setStartOffset(long offset, TimeUnit units) {
checkNotNull(units);
this.startOffset = units.toMillis(offset);
return getThis();
} | java | public T setStartOffset(long offset, TimeUnit units) {
checkNotNull(units);
this.startOffset = units.toMillis(offset);
return getThis();
} | [
"public",
"T",
"setStartOffset",
"(",
"long",
"offset",
",",
"TimeUnit",
"units",
")",
"{",
"checkNotNull",
"(",
"units",
")",
";",
"this",
".",
"startOffset",
"=",
"units",
".",
"toMillis",
"(",
"offset",
")",
";",
"return",
"getThis",
"(",
")",
";",
... | Decodes but discards input until the offset.
@param offset The offset
@param units The units the offset is in
@return this | [
"Decodes",
"but",
"discards",
"input",
"until",
"the",
"offset",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L432-L438 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setDuration | public T setDuration(long duration, TimeUnit units) {
checkNotNull(units);
this.duration = units.toMillis(duration);
return getThis();
} | java | public T setDuration(long duration, TimeUnit units) {
checkNotNull(units);
this.duration = units.toMillis(duration);
return getThis();
} | [
"public",
"T",
"setDuration",
"(",
"long",
"duration",
",",
"TimeUnit",
"units",
")",
"{",
"checkNotNull",
"(",
"units",
")",
";",
"this",
".",
"duration",
"=",
"units",
".",
"toMillis",
"(",
"duration",
")",
";",
"return",
"getThis",
"(",
")",
";",
"}... | Stop writing the output after duration is reached.
@param duration The duration
@param units The units the duration is in
@return this | [
"Stop",
"writing",
"the",
"output",
"after",
"duration",
"is",
"reached",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L447-L453 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setAudioPreset | public T setAudioPreset(String preset) {
this.audio_enabled = true;
this.audio_preset = checkNotEmpty(preset, "audio preset must not be empty");
return getThis();
} | java | public T setAudioPreset(String preset) {
this.audio_enabled = true;
this.audio_preset = checkNotEmpty(preset, "audio preset must not be empty");
return getThis();
} | [
"public",
"T",
"setAudioPreset",
"(",
"String",
"preset",
")",
"{",
"this",
".",
"audio_enabled",
"=",
"true",
";",
"this",
".",
"audio_preset",
"=",
"checkNotEmpty",
"(",
"preset",
",",
"\"audio preset must not be empty\"",
")",
";",
"return",
"getThis",
"(",
... | Sets a audio preset to use.
<p>Uses `-apre`.
@param preset the preset
@return this | [
"Sets",
"a",
"audio",
"preset",
"to",
"use",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L480-L484 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java | AbstractFFmpegStreamBuilder.setSubtitlePreset | public T setSubtitlePreset(String preset) {
this.subtitle_enabled = true;
this.subtitle_preset = checkNotEmpty(preset, "subtitle preset must not be empty");
return getThis();
} | java | public T setSubtitlePreset(String preset) {
this.subtitle_enabled = true;
this.subtitle_preset = checkNotEmpty(preset, "subtitle preset must not be empty");
return getThis();
} | [
"public",
"T",
"setSubtitlePreset",
"(",
"String",
"preset",
")",
"{",
"this",
".",
"subtitle_enabled",
"=",
"true",
";",
"this",
".",
"subtitle_preset",
"=",
"checkNotEmpty",
"(",
"preset",
",",
"\"subtitle preset must not be empty\"",
")",
";",
"return",
"getThi... | Sets a subtitle preset to use.
<p>Uses `-spre`.
@param preset the preset
@return this | [
"Sets",
"a",
"subtitle",
"preset",
"to",
"use",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java#L494-L498 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java | NutDataInputStream.readVarInt | public int readVarInt() throws IOException {
boolean more;
int result = 0;
do {
int b = in.readUnsignedByte();
more = (b & 0x80) == 0x80;
result = 128 * result + (b & 0x7F);
// TODO Check for int overflow
} while (more);
return result;
} | java | public int readVarInt() throws IOException {
boolean more;
int result = 0;
do {
int b = in.readUnsignedByte();
more = (b & 0x80) == 0x80;
result = 128 * result + (b & 0x7F);
// TODO Check for int overflow
} while (more);
return result;
} | [
"public",
"int",
"readVarInt",
"(",
")",
"throws",
"IOException",
"{",
"boolean",
"more",
";",
"int",
"result",
"=",
"0",
";",
"do",
"{",
"int",
"b",
"=",
"in",
".",
"readUnsignedByte",
"(",
")",
";",
"more",
"=",
"(",
"b",
"&",
"0x80",
")",
"==",
... | Read a simple var int up to 32 bits | [
"Read",
"a",
"simple",
"var",
"int",
"up",
"to",
"32",
"bits"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java#L42-L54 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java | NutDataInputStream.readVarLong | public long readVarLong() throws IOException {
boolean more;
long result = 0;
do {
int b = in.readUnsignedByte();
more = (b & 0x80) == 0x80;
result = 128 * result + (b & 0x7F);
// TODO Check for long overflow
} while (more);
return result;
} | java | public long readVarLong() throws IOException {
boolean more;
long result = 0;
do {
int b = in.readUnsignedByte();
more = (b & 0x80) == 0x80;
result = 128 * result + (b & 0x7F);
// TODO Check for long overflow
} while (more);
return result;
} | [
"public",
"long",
"readVarLong",
"(",
")",
"throws",
"IOException",
"{",
"boolean",
"more",
";",
"long",
"result",
"=",
"0",
";",
"do",
"{",
"int",
"b",
"=",
"in",
".",
"readUnsignedByte",
"(",
")",
";",
"more",
"=",
"(",
"b",
"&",
"0x80",
")",
"==... | Read a simple var int up to 64 bits | [
"Read",
"a",
"simple",
"var",
"int",
"up",
"to",
"64",
"bits"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java#L57-L69 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java | NutDataInputStream.readVarArray | public byte[] readVarArray() throws IOException {
int len = (int) readVarLong();
byte[] result = new byte[len];
in.read(result);
return result;
} | java | public byte[] readVarArray() throws IOException {
int len = (int) readVarLong();
byte[] result = new byte[len];
in.read(result);
return result;
} | [
"public",
"byte",
"[",
"]",
"readVarArray",
"(",
")",
"throws",
"IOException",
"{",
"int",
"len",
"=",
"(",
"int",
")",
"readVarLong",
"(",
")",
";",
"byte",
"[",
"]",
"result",
"=",
"new",
"byte",
"[",
"len",
"]",
";",
"in",
".",
"read",
"(",
"r... | Read a array with a varint prefixed length | [
"Read",
"a",
"array",
"with",
"a",
"varint",
"prefixed",
"length"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java#L81-L86 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java | NutDataInputStream.readStartCode | public long readStartCode() throws IOException {
byte frameCode = in.readByte();
if (frameCode != 'N') {
return (long) (frameCode & 0xff);
}
// Otherwise read the remaining 64bit startCode
byte[] buffer = new byte[8];
buffer[0] = frameCode;
readFully(buffer, 1, 7);
return (((long) buffer[0] << 56)
+ ((long) (buffer[1] & 255) << 48)
+ ((long) (buffer[2] & 255) << 40)
+ ((long) (buffer[3] & 255) << 32)
+ ((long) (buffer[4] & 255) << 24)
+ ((buffer[5] & 255) << 16)
+ ((buffer[6] & 255) << 8)
+ ((buffer[7] & 255) << 0));
} | java | public long readStartCode() throws IOException {
byte frameCode = in.readByte();
if (frameCode != 'N') {
return (long) (frameCode & 0xff);
}
// Otherwise read the remaining 64bit startCode
byte[] buffer = new byte[8];
buffer[0] = frameCode;
readFully(buffer, 1, 7);
return (((long) buffer[0] << 56)
+ ((long) (buffer[1] & 255) << 48)
+ ((long) (buffer[2] & 255) << 40)
+ ((long) (buffer[3] & 255) << 32)
+ ((long) (buffer[4] & 255) << 24)
+ ((buffer[5] & 255) << 16)
+ ((buffer[6] & 255) << 8)
+ ((buffer[7] & 255) << 0));
} | [
"public",
"long",
"readStartCode",
"(",
")",
"throws",
"IOException",
"{",
"byte",
"frameCode",
"=",
"in",
".",
"readByte",
"(",
")",
";",
"if",
"(",
"frameCode",
"!=",
"'",
"'",
")",
"{",
"return",
"(",
"long",
")",
"(",
"frameCode",
"&",
"0xff",
")... | Returns the start code, OR frame_code if the code doesn't start with 'N' | [
"Returns",
"the",
"start",
"code",
"OR",
"frame_code",
"if",
"the",
"code",
"doesn",
"t",
"start",
"with",
"N"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/nut/NutDataInputStream.java#L89-L107 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/StreamSpecifier.java | StreamSpecifier.stream | public static StreamSpecifier stream(StreamSpecifierType type, int index) {
checkNotNull(type);
return new StreamSpecifier(type.toString() + ":" + index);
} | java | public static StreamSpecifier stream(StreamSpecifierType type, int index) {
checkNotNull(type);
return new StreamSpecifier(type.toString() + ":" + index);
} | [
"public",
"static",
"StreamSpecifier",
"stream",
"(",
"StreamSpecifierType",
"type",
",",
"int",
"index",
")",
"{",
"checkNotNull",
"(",
"type",
")",
";",
"return",
"new",
"StreamSpecifier",
"(",
"type",
".",
"toString",
"(",
")",
"+",
"\":\"",
"+",
"index",... | Matches the stream number stream_index of this type.
@param type The stream type
@param index The stream index
@return A new StreamSpecifier | [
"Matches",
"the",
"stream",
"number",
"stream_index",
"of",
"this",
"type",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/StreamSpecifier.java#L47-L50 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/builder/StreamSpecifier.java | StreamSpecifier.tag | public static StreamSpecifier tag(String key, String value) {
checkValidKey(key);
checkNotNull(value);
return new StreamSpecifier("m:" + key + ":" + value);
} | java | public static StreamSpecifier tag(String key, String value) {
checkValidKey(key);
checkNotNull(value);
return new StreamSpecifier("m:" + key + ":" + value);
} | [
"public",
"static",
"StreamSpecifier",
"tag",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"checkValidKey",
"(",
"key",
")",
";",
"checkNotNull",
"(",
"value",
")",
";",
"return",
"new",
"StreamSpecifier",
"(",
"\"m:\"",
"+",
"key",
"+",
"\":\""... | Matches streams with the metadata tag key having the specified value.
@param key The metadata tag
@param value The metatdata's value
@return A new StreamSpecifier | [
"Matches",
"streams",
"with",
"the",
"metadata",
"tag",
"key",
"having",
"the",
"specified",
"value",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/builder/StreamSpecifier.java#L100-L104 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/progress/Progress.java | Progress.parseLine | protected boolean parseLine(String line) {
line = checkNotNull(line).trim();
if (line.isEmpty()) {
return false; // Skip empty lines
}
final String[] args = line.split("=", 2);
if (args.length != 2) {
// invalid argument, so skip
return false;
}
final String key = checkNotNull(args[0]);
final String value = checkNotNull(args[1]);
switch (key) {
case "frame":
frame = Long.parseLong(value);
return false;
case "fps":
fps = Fraction.getFraction(value);
return false;
case "bitrate":
if (value.equals("N/A")) {
bitrate = -1;
} else {
bitrate = FFmpegUtils.parseBitrate(value);
}
return false;
case "total_size":
if (value.equals("N/A")) {
total_size = -1;
} else {
total_size = Long.parseLong(value);
}
return false;
case "out_time_ms":
// This is a duplicate of the "out_time" field, but expressed as a int instead of string.
// Note this value is in microseconds, not milliseconds, and is based on AV_TIME_BASE which
// could change.
// out_time_ns = Long.parseLong(value) * 1000;
return false;
case "out_time":
out_time_ns = fromTimecode(value);
return false;
case "dup_frames":
dup_frames = Long.parseLong(value);
return false;
case "drop_frames":
drop_frames = Long.parseLong(value);
return false;
case "speed":
if (value.equals("N/A")) {
speed = -1;
} else {
speed = Float.parseFloat(value.replace("x", ""));
}
return false;
case "progress":
// TODO After "end" stream is closed
status = Status.of(value);
return true; // The status field is always last in the record
default:
if (key.startsWith("stream_")) {
// TODO handle stream_0_0_q=0.0:
// stream_%d_%d_q= file_index, index, quality
// stream_%d_%d_psnr_%c=%2.2f, file_index, index, type{Y, U, V}, quality // Enable with
// AV_CODEC_FLAG_PSNR
// stream_%d_%d_psnr_all
} else {
LOG.warn("skipping unhandled key: {} = {}", key, value);
}
return false; // Either way, not supported
}
} | java | protected boolean parseLine(String line) {
line = checkNotNull(line).trim();
if (line.isEmpty()) {
return false; // Skip empty lines
}
final String[] args = line.split("=", 2);
if (args.length != 2) {
// invalid argument, so skip
return false;
}
final String key = checkNotNull(args[0]);
final String value = checkNotNull(args[1]);
switch (key) {
case "frame":
frame = Long.parseLong(value);
return false;
case "fps":
fps = Fraction.getFraction(value);
return false;
case "bitrate":
if (value.equals("N/A")) {
bitrate = -1;
} else {
bitrate = FFmpegUtils.parseBitrate(value);
}
return false;
case "total_size":
if (value.equals("N/A")) {
total_size = -1;
} else {
total_size = Long.parseLong(value);
}
return false;
case "out_time_ms":
// This is a duplicate of the "out_time" field, but expressed as a int instead of string.
// Note this value is in microseconds, not milliseconds, and is based on AV_TIME_BASE which
// could change.
// out_time_ns = Long.parseLong(value) * 1000;
return false;
case "out_time":
out_time_ns = fromTimecode(value);
return false;
case "dup_frames":
dup_frames = Long.parseLong(value);
return false;
case "drop_frames":
drop_frames = Long.parseLong(value);
return false;
case "speed":
if (value.equals("N/A")) {
speed = -1;
} else {
speed = Float.parseFloat(value.replace("x", ""));
}
return false;
case "progress":
// TODO After "end" stream is closed
status = Status.of(value);
return true; // The status field is always last in the record
default:
if (key.startsWith("stream_")) {
// TODO handle stream_0_0_q=0.0:
// stream_%d_%d_q= file_index, index, quality
// stream_%d_%d_psnr_%c=%2.2f, file_index, index, type{Y, U, V}, quality // Enable with
// AV_CODEC_FLAG_PSNR
// stream_%d_%d_psnr_all
} else {
LOG.warn("skipping unhandled key: {} = {}", key, value);
}
return false; // Either way, not supported
}
} | [
"protected",
"boolean",
"parseLine",
"(",
"String",
"line",
")",
"{",
"line",
"=",
"checkNotNull",
"(",
"line",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"line",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"// Skip empty lines",
"}",
... | Parses values from the line, into this object.
<p>The value options are defined in ffmpeg.c's print_report function
https://github.com/FFmpeg/FFmpeg/blob/master/ffmpeg.c
@param line A single line of output from ffmpeg
@return true if the record is finished | [
"Parses",
"values",
"from",
"the",
"line",
"into",
"this",
"object",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/progress/Progress.java#L114-L199 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/progress/AbstractSocketProgressParser.java | AbstractSocketProgressParser.createUri | @CheckReturnValue
static URI createUri(String scheme, InetAddress address, int port) throws URISyntaxException {
checkNotNull(address);
return new URI(
scheme,
null /* userInfo */,
InetAddresses.toUriString(address),
port,
null /* path */,
null /* query */,
null /* fragment */);
} | java | @CheckReturnValue
static URI createUri(String scheme, InetAddress address, int port) throws URISyntaxException {
checkNotNull(address);
return new URI(
scheme,
null /* userInfo */,
InetAddresses.toUriString(address),
port,
null /* path */,
null /* query */,
null /* fragment */);
} | [
"@",
"CheckReturnValue",
"static",
"URI",
"createUri",
"(",
"String",
"scheme",
",",
"InetAddress",
"address",
",",
"int",
"port",
")",
"throws",
"URISyntaxException",
"{",
"checkNotNull",
"(",
"address",
")",
";",
"return",
"new",
"URI",
"(",
"scheme",
",",
... | Creates a URL to parse to FFmpeg based on the scheme, address and port.
<p>TODO Move this method to somewhere better.
@param scheme
@param address
@param port
@return
@throws URISyntaxException | [
"Creates",
"a",
"URL",
"to",
"parse",
"to",
"FFmpeg",
"based",
"on",
"the",
"scheme",
"address",
"and",
"port",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/progress/AbstractSocketProgressParser.java#L35-L46 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/progress/AbstractSocketProgressParser.java | AbstractSocketProgressParser.start | @Override
public synchronized void start() {
if (thread != null) {
throw new IllegalThreadStateException("Parser already started");
}
String name = getThreadName() + "(" + getUri().toString() + ")";
CountDownLatch startSignal = new CountDownLatch(1);
Runnable runnable = getRunnable(startSignal);
thread = new Thread(runnable, name);
thread.start();
// Block until the thread has started
try {
startSignal.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} | java | @Override
public synchronized void start() {
if (thread != null) {
throw new IllegalThreadStateException("Parser already started");
}
String name = getThreadName() + "(" + getUri().toString() + ")";
CountDownLatch startSignal = new CountDownLatch(1);
Runnable runnable = getRunnable(startSignal);
thread = new Thread(runnable, name);
thread.start();
// Block until the thread has started
try {
startSignal.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} | [
"@",
"Override",
"public",
"synchronized",
"void",
"start",
"(",
")",
"{",
"if",
"(",
"thread",
"!=",
"null",
")",
"{",
"throw",
"new",
"IllegalThreadStateException",
"(",
"\"Parser already started\"",
")",
";",
"}",
"String",
"name",
"=",
"getThreadName",
"("... | Starts the ProgressParser waiting for progress.
@exception IllegalThreadStateException if the parser was already started. | [
"Starts",
"the",
"ProgressParser",
"waiting",
"for",
"progress",
"."
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/progress/AbstractSocketProgressParser.java#L58-L78 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/FFmpegUtils.java | FFmpegUtils.parseBitrate | public static long parseBitrate(String bitrate) {
if ("N/A".equals(bitrate)) {
return -1;
}
Matcher m = BITRATE_REGEX.matcher(bitrate);
if (!m.find()) {
throw new IllegalArgumentException("Invalid bitrate '" + bitrate + "'");
}
return (long) (Float.parseFloat(m.group(1)) * 1000);
} | java | public static long parseBitrate(String bitrate) {
if ("N/A".equals(bitrate)) {
return -1;
}
Matcher m = BITRATE_REGEX.matcher(bitrate);
if (!m.find()) {
throw new IllegalArgumentException("Invalid bitrate '" + bitrate + "'");
}
return (long) (Float.parseFloat(m.group(1)) * 1000);
} | [
"public",
"static",
"long",
"parseBitrate",
"(",
"String",
"bitrate",
")",
"{",
"if",
"(",
"\"N/A\"",
".",
"equals",
"(",
"bitrate",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"Matcher",
"m",
"=",
"BITRATE_REGEX",
".",
"matcher",
"(",
"bitrate",
")",... | Converts a string representation of bitrate to a long of bits per second
@param bitrate in the form of 12.3kbits/s
@return the bitrate in bits per second or -1 if bitrate is 'N/A' | [
"Converts",
"a",
"string",
"representation",
"of",
"bitrate",
"to",
"a",
"long",
"of",
"bits",
"per",
"second"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/FFmpegUtils.java#L100-L110 | train |
bramp/ffmpeg-cli-wrapper | src/main/java/net/bramp/ffmpeg/io/ProcessUtils.java | ProcessUtils.waitForWithTimeout | public static int waitForWithTimeout(final Process p, long timeout, TimeUnit unit)
throws TimeoutException {
ProcessThread t = new ProcessThread(p);
t.start();
try {
unit.timedJoin(t, timeout);
} catch (InterruptedException e) {
t.interrupt();
Thread.currentThread().interrupt();
}
if (!t.hasFinished()) {
throw new TimeoutException("Process did not finish within timeout");
}
return t.exitValue();
} | java | public static int waitForWithTimeout(final Process p, long timeout, TimeUnit unit)
throws TimeoutException {
ProcessThread t = new ProcessThread(p);
t.start();
try {
unit.timedJoin(t, timeout);
} catch (InterruptedException e) {
t.interrupt();
Thread.currentThread().interrupt();
}
if (!t.hasFinished()) {
throw new TimeoutException("Process did not finish within timeout");
}
return t.exitValue();
} | [
"public",
"static",
"int",
"waitForWithTimeout",
"(",
"final",
"Process",
"p",
",",
"long",
"timeout",
",",
"TimeUnit",
"unit",
")",
"throws",
"TimeoutException",
"{",
"ProcessThread",
"t",
"=",
"new",
"ProcessThread",
"(",
"p",
")",
";",
"t",
".",
"start",
... | Waits until a process finishes or a timeout occurs
@param p process
@param timeout timeout in given unit
@param unit time unit
@return the process exit value
@throws TimeoutException if a timeout occurs | [
"Waits",
"until",
"a",
"process",
"finishes",
"or",
"a",
"timeout",
"occurs"
] | 3819b155edf9132acc75bb6af66dcef1b98c64b2 | https://github.com/bramp/ffmpeg-cli-wrapper/blob/3819b155edf9132acc75bb6af66dcef1b98c64b2/src/main/java/net/bramp/ffmpeg/io/ProcessUtils.java#L50-L68 | train |
minio/minio-java | api/src/main/java/io/minio/Result.java | Result.get | public T get()
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (ex == null) {
return type;
}
if (ex instanceof InvalidBucketNameException) {
throw (InvalidBucketNameException) ex;
} else if (ex instanceof NoSuchAlgorithmException) {
throw (NoSuchAlgorithmException) ex;
} else if (ex instanceof InsufficientDataException) {
throw (InsufficientDataException) ex;
} else if (ex instanceof IOException) {
throw (IOException) ex;
} else if (ex instanceof InvalidKeyException) {
throw (InvalidKeyException) ex;
} else if (ex instanceof NoResponseException) {
throw (NoResponseException) ex;
} else if (ex instanceof XmlPullParserException) {
throw (XmlPullParserException) ex;
} else if (ex instanceof ErrorResponseException) {
throw (ErrorResponseException) ex;
} else {
throw (InternalException) ex;
}
} | java | public T get()
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (ex == null) {
return type;
}
if (ex instanceof InvalidBucketNameException) {
throw (InvalidBucketNameException) ex;
} else if (ex instanceof NoSuchAlgorithmException) {
throw (NoSuchAlgorithmException) ex;
} else if (ex instanceof InsufficientDataException) {
throw (InsufficientDataException) ex;
} else if (ex instanceof IOException) {
throw (IOException) ex;
} else if (ex instanceof InvalidKeyException) {
throw (InvalidKeyException) ex;
} else if (ex instanceof NoResponseException) {
throw (NoResponseException) ex;
} else if (ex instanceof XmlPullParserException) {
throw (XmlPullParserException) ex;
} else if (ex instanceof ErrorResponseException) {
throw (ErrorResponseException) ex;
} else {
throw (InternalException) ex;
}
} | [
"public",
"T",
"get",
"(",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullParserException",
",",
"ErrorResponseException",... | Returns given Type if exception is null, else respective exception is thrown. | [
"Returns",
"given",
"Type",
"if",
"exception",
"is",
"null",
"else",
"respective",
"exception",
"is",
"thrown",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/Result.java#L49-L76 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.isValidEndpoint | private boolean isValidEndpoint(String endpoint) {
if (InetAddressValidator.getInstance().isValid(endpoint)) {
return true;
}
// endpoint may be a hostname
// refer https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
// why checks are done like below
if (endpoint.length() < 1 || endpoint.length() > 253) {
return false;
}
for (String label : endpoint.split("\\.")) {
if (label.length() < 1 || label.length() > 63) {
return false;
}
if (!(label.matches("^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$"))) {
return false;
}
}
return true;
} | java | private boolean isValidEndpoint(String endpoint) {
if (InetAddressValidator.getInstance().isValid(endpoint)) {
return true;
}
// endpoint may be a hostname
// refer https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
// why checks are done like below
if (endpoint.length() < 1 || endpoint.length() > 253) {
return false;
}
for (String label : endpoint.split("\\.")) {
if (label.length() < 1 || label.length() > 63) {
return false;
}
if (!(label.matches("^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$"))) {
return false;
}
}
return true;
} | [
"private",
"boolean",
"isValidEndpoint",
"(",
"String",
"endpoint",
")",
"{",
"if",
"(",
"InetAddressValidator",
".",
"getInstance",
"(",
")",
".",
"isValid",
"(",
"endpoint",
")",
")",
"{",
"return",
"true",
";",
"}",
"// endpoint may be a hostname",
"// refer ... | Returns true if given endpoint is valid else false. | [
"Returns",
"true",
"if",
"given",
"endpoint",
"is",
"valid",
"else",
"false",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L728-L751 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.checkBucketName | private void checkBucketName(String name) throws InvalidBucketNameException {
if (name == null) {
throw new InvalidBucketNameException(NULL_STRING, "null bucket name");
}
// Bucket names cannot be no less than 3 and no more than 63 characters long.
if (name.length() < 3 || name.length() > 63) {
String msg = "bucket name must be at least 3 and no more than 63 characters long";
throw new InvalidBucketNameException(name, msg);
}
// Successive periods in bucket names are not allowed.
if (name.matches("\\.\\.")) {
String msg = "bucket name cannot contain successive periods. For more information refer "
+ "http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html";
throw new InvalidBucketNameException(name, msg);
}
// Bucket names should be dns compatible.
if (!name.matches("^[a-z0-9][a-z0-9\\.\\-]+[a-z0-9]$")) {
String msg = "bucket name does not follow Amazon S3 standards. For more information refer "
+ "http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html";
throw new InvalidBucketNameException(name, msg);
}
} | java | private void checkBucketName(String name) throws InvalidBucketNameException {
if (name == null) {
throw new InvalidBucketNameException(NULL_STRING, "null bucket name");
}
// Bucket names cannot be no less than 3 and no more than 63 characters long.
if (name.length() < 3 || name.length() > 63) {
String msg = "bucket name must be at least 3 and no more than 63 characters long";
throw new InvalidBucketNameException(name, msg);
}
// Successive periods in bucket names are not allowed.
if (name.matches("\\.\\.")) {
String msg = "bucket name cannot contain successive periods. For more information refer "
+ "http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html";
throw new InvalidBucketNameException(name, msg);
}
// Bucket names should be dns compatible.
if (!name.matches("^[a-z0-9][a-z0-9\\.\\-]+[a-z0-9]$")) {
String msg = "bucket name does not follow Amazon S3 standards. For more information refer "
+ "http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html";
throw new InvalidBucketNameException(name, msg);
}
} | [
"private",
"void",
"checkBucketName",
"(",
"String",
"name",
")",
"throws",
"InvalidBucketNameException",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidBucketNameException",
"(",
"NULL_STRING",
",",
"\"null bucket name\"",
")",
";",
"}",
... | Validates if given bucket name is DNS compatible.
@throws InvalidBucketNameException upon invalid bucket name is given | [
"Validates",
"if",
"given",
"bucket",
"name",
"is",
"DNS",
"compatible",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L759-L781 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.setTimeout | public void setTimeout(long connectTimeout, long writeTimeout, long readTimeout) {
this.httpClient = this.httpClient.newBuilder()
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
.build();
} | java | public void setTimeout(long connectTimeout, long writeTimeout, long readTimeout) {
this.httpClient = this.httpClient.newBuilder()
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
.build();
} | [
"public",
"void",
"setTimeout",
"(",
"long",
"connectTimeout",
",",
"long",
"writeTimeout",
",",
"long",
"readTimeout",
")",
"{",
"this",
".",
"httpClient",
"=",
"this",
".",
"httpClient",
".",
"newBuilder",
"(",
")",
".",
"connectTimeout",
"(",
"connectTimeou... | Sets HTTP connect, write and read timeouts. A value of 0 means no timeout, otherwise values must be between 1 and
Integer.MAX_VALUE when converted to milliseconds.
</p><b>Example:</b><br>
<pre>{@code minioClient.setTimeout(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(10),
TimeUnit.SECONDS.toMillis(30)); }</pre>
@param connectTimeout HTTP connect timeout in milliseconds.
@param writeTimeout HTTP write timeout in milliseconds.
@param readTimeout HTTP read timeout in milliseconds. | [
"Sets",
"HTTP",
"connect",
"write",
"and",
"read",
"timeouts",
".",
"A",
"value",
"of",
"0",
"means",
"no",
"timeout",
"otherwise",
"values",
"must",
"be",
"between",
"1",
"and",
"Integer",
".",
"MAX_VALUE",
"when",
"converted",
"to",
"milliseconds",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L796-L802 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.ignoreCertCheck | @SuppressFBWarnings(value = "SIC", justification = "Should not be used in production anyways.")
public void ignoreCertCheck() throws NoSuchAlgorithmException, KeyManagementException {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
this.httpClient = this.httpClient.newBuilder()
.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0])
.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
})
.build();
} | java | @SuppressFBWarnings(value = "SIC", justification = "Should not be used in production anyways.")
public void ignoreCertCheck() throws NoSuchAlgorithmException, KeyManagementException {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
this.httpClient = this.httpClient.newBuilder()
.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0])
.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
})
.build();
} | [
"@",
"SuppressFBWarnings",
"(",
"value",
"=",
"\"SIC\"",
",",
"justification",
"=",
"\"Should not be used in production anyways.\"",
")",
"public",
"void",
"ignoreCertCheck",
"(",
")",
"throws",
"NoSuchAlgorithmException",
",",
"KeyManagementException",
"{",
"final",
"Tru... | Ignores check on server certificate for HTTPS connection.
</p><b>Example:</b><br>
<pre>{@code minioClient.ignoreCertCheck(); }</pre> | [
"Ignores",
"check",
"on",
"server",
"certificate",
"for",
"HTTPS",
"connection",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L812-L843 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.shouldOmitPortInHostHeader | private boolean shouldOmitPortInHostHeader(HttpUrl url) {
return (url.scheme().equals("http") && url.port() == 80)
|| (url.scheme().equals("https") && url.port() == 443);
} | java | private boolean shouldOmitPortInHostHeader(HttpUrl url) {
return (url.scheme().equals("http") && url.port() == 80)
|| (url.scheme().equals("https") && url.port() == 443);
} | [
"private",
"boolean",
"shouldOmitPortInHostHeader",
"(",
"HttpUrl",
"url",
")",
"{",
"return",
"(",
"url",
".",
"scheme",
"(",
")",
".",
"equals",
"(",
"\"http\"",
")",
"&&",
"url",
".",
"port",
"(",
")",
"==",
"80",
")",
"||",
"(",
"url",
".",
"sche... | Checks whether port should be omitted in Host header.
<p>
HTTP Spec (rfc2616) defines that port should be omitted in Host header
when port and service matches (i.e HTTP -> 80, HTTPS -> 443)
@param url Url object | [
"Checks",
"whether",
"port",
"should",
"be",
"omitted",
"in",
"Host",
"header",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1031-L1034 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.execute | private HttpResponse execute(Method method, String region, String bucketName, String objectName,
Map<String,String> headerMap, Map<String,String> queryParamMap,
Object body, int length)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (headerMap != null) {
headerMap = normalizeHeaders(headerMap);
}
Multimap<String, String> queryParamMultiMap = null;
if (queryParamMap != null) {
queryParamMultiMap = Multimaps.forMap(queryParamMap);
}
Multimap<String, String> headerMultiMap = null;
if (headerMap != null) {
headerMultiMap = Multimaps.forMap(headerMap);
}
return executeReq(method, region, bucketName, objectName, headerMultiMap, queryParamMultiMap, body, length);
} | java | private HttpResponse execute(Method method, String region, String bucketName, String objectName,
Map<String,String> headerMap, Map<String,String> queryParamMap,
Object body, int length)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (headerMap != null) {
headerMap = normalizeHeaders(headerMap);
}
Multimap<String, String> queryParamMultiMap = null;
if (queryParamMap != null) {
queryParamMultiMap = Multimaps.forMap(queryParamMap);
}
Multimap<String, String> headerMultiMap = null;
if (headerMap != null) {
headerMultiMap = Multimaps.forMap(headerMap);
}
return executeReq(method, region, bucketName, objectName, headerMultiMap, queryParamMultiMap, body, length);
} | [
"private",
"HttpResponse",
"execute",
"(",
"Method",
"method",
",",
"String",
"region",
",",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
",",
"Map",
"<",
"String",
",",
"String",
">",
"qu... | Executes given request parameters.
@param method HTTP method.
@param region Amazon S3 region of the bucket.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param headerMap Map of HTTP headers for the request.
@param queryParamMap Map of HTTP query parameters of the request.
@param body HTTP request body.
@param length Length of HTTP request body. | [
"Executes",
"given",
"request",
"parameters",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1049-L1071 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.updateRegionCache | private void updateRegionCache(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (bucketName != null && this.accessKey != null && this.secretKey != null
&& !BucketRegionCache.INSTANCE.exists(bucketName)) {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("location", null);
HttpResponse response = execute(Method.GET, US_EAST_1, bucketName, "/",
null, queryParamMap, null, 0);
// existing XmlEntity does not work, so fallback to regular parsing.
XmlPullParser xpp = xmlPullParserFactory.newPullParser();
String location = null;
try (ResponseBody body = response.body()) {
xpp.setInput(body.charStream());
while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
if (xpp.getEventType() == XmlPullParser.START_TAG && "LocationConstraint".equals(xpp.getName())) {
xpp.next();
location = getText(xpp);
break;
}
xpp.next();
}
}
String region;
if (location == null) {
region = US_EAST_1;
} else {
// eu-west-1 can be sometimes 'EU'.
if ("EU".equals(location)) {
region = "eu-west-1";
} else {
region = location;
}
}
// Add the new location.
BucketRegionCache.INSTANCE.set(bucketName, region);
}
} | java | private void updateRegionCache(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
if (bucketName != null && this.accessKey != null && this.secretKey != null
&& !BucketRegionCache.INSTANCE.exists(bucketName)) {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("location", null);
HttpResponse response = execute(Method.GET, US_EAST_1, bucketName, "/",
null, queryParamMap, null, 0);
// existing XmlEntity does not work, so fallback to regular parsing.
XmlPullParser xpp = xmlPullParserFactory.newPullParser();
String location = null;
try (ResponseBody body = response.body()) {
xpp.setInput(body.charStream());
while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
if (xpp.getEventType() == XmlPullParser.START_TAG && "LocationConstraint".equals(xpp.getName())) {
xpp.next();
location = getText(xpp);
break;
}
xpp.next();
}
}
String region;
if (location == null) {
region = US_EAST_1;
} else {
// eu-west-1 can be sometimes 'EU'.
if ("EU".equals(location)) {
region = "eu-west-1";
} else {
region = location;
}
}
// Add the new location.
BucketRegionCache.INSTANCE.set(bucketName, region);
}
} | [
"private",
"void",
"updateRegionCache",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullParser... | Updates Region cache for given bucket. | [
"Updates",
"Region",
"cache",
"for",
"given",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1210-L1253 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getRegion | private String getRegion(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException,
ErrorResponseException, InternalException {
String region;
if (this.region == null || "".equals(this.region)) {
updateRegionCache(bucketName);
region = BucketRegionCache.INSTANCE.region(bucketName);
} else {
region = this.region;
}
return region;
} | java | private String getRegion(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException,
ErrorResponseException, InternalException {
String region;
if (this.region == null || "".equals(this.region)) {
updateRegionCache(bucketName);
region = BucketRegionCache.INSTANCE.region(bucketName);
} else {
region = this.region;
}
return region;
} | [
"private",
"String",
"getRegion",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullParserExcept... | Computes region of a given bucket name. If set, this.region is considered. Otherwise,
resort to the server location API. | [
"Computes",
"region",
"of",
"a",
"given",
"bucket",
"name",
".",
"If",
"set",
"this",
".",
"region",
"is",
"considered",
".",
"Otherwise",
"resort",
"to",
"the",
"server",
"location",
"API",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1259-L1270 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getText | private String getText(XmlPullParser xpp) throws XmlPullParserException {
if (xpp.getEventType() == XmlPullParser.TEXT) {
return xpp.getText();
}
return null;
} | java | private String getText(XmlPullParser xpp) throws XmlPullParserException {
if (xpp.getEventType() == XmlPullParser.TEXT) {
return xpp.getText();
}
return null;
} | [
"private",
"String",
"getText",
"(",
"XmlPullParser",
"xpp",
")",
"throws",
"XmlPullParserException",
"{",
"if",
"(",
"xpp",
".",
"getEventType",
"(",
")",
"==",
"XmlPullParser",
".",
"TEXT",
")",
"{",
"return",
"xpp",
".",
"getText",
"(",
")",
";",
"}",
... | Returns text of given XML element.
@throws XmlPullParserException upon parsing response xml | [
"Returns",
"text",
"of",
"given",
"XML",
"element",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1277-L1282 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.executeGet | private HttpResponse executeGet(String bucketName, String objectName, Map<String,String> headerMap,
Map<String,String> queryParamMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
return execute(Method.GET, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, null, 0);
} | java | private HttpResponse executeGet(String bucketName, String objectName, Map<String,String> headerMap,
Map<String,String> queryParamMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
return execute(Method.GET, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, null, 0);
} | [
"private",
"HttpResponse",
"executeGet",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
",",
"Map",
"<",
"String",
",",
"String",
">",
"queryParamMap",
")",
"throws",
"InvalidBucketNameExcept... | Executes GET method for given request parameters.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param headerMap Map of HTTP headers for the request.
@param queryParamMap Map of HTTP query parameters of the request. | [
"Executes",
"GET",
"method",
"for",
"given",
"request",
"parameters",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1293-L1299 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.executeHead | private HttpResponse executeHead(String bucketName, String objectName, Map<String,String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = execute(Method.HEAD, getRegion(bucketName), bucketName, objectName, headerMap,
null, null, 0);
response.body().close();
return response;
} | java | private HttpResponse executeHead(String bucketName, String objectName, Map<String,String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = execute(Method.HEAD, getRegion(bucketName), bucketName, objectName, headerMap,
null, null, 0);
response.body().close();
return response;
} | [
"private",
"HttpResponse",
"executeHead",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException"... | Executes HEAD method for given request parameters.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param headerMap Map of header parameters of the request. | [
"Executes",
"HEAD",
"method",
"for",
"given",
"request",
"parameters",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1325-L1334 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.executeDelete | private HttpResponse executeDelete(String bucketName, String objectName, Map<String,String> queryParamMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = execute(Method.DELETE, getRegion(bucketName), bucketName, objectName, null,
queryParamMap, null, 0);
response.body().close();
return response;
} | java | private HttpResponse executeDelete(String bucketName, String objectName, Map<String,String> queryParamMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = execute(Method.DELETE, getRegion(bucketName), bucketName, objectName, null,
queryParamMap, null, 0);
response.body().close();
return response;
} | [
"private",
"HttpResponse",
"executeDelete",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"queryParamMap",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataExce... | Executes DELETE method for given request parameters.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param queryParamMap Map of HTTP query parameters of the request. | [
"Executes",
"DELETE",
"method",
"for",
"given",
"request",
"parameters",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1343-L1351 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.executePost | private HttpResponse executePost(String bucketName, String objectName, Map<String,String> headerMap,
Map<String,String> queryParamMap, Object data)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
return execute(Method.POST, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, data, 0);
} | java | private HttpResponse executePost(String bucketName, String objectName, Map<String,String> headerMap,
Map<String,String> queryParamMap, Object data)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
return execute(Method.POST, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, data, 0);
} | [
"private",
"HttpResponse",
"executePost",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
",",
"Map",
"<",
"String",
",",
"String",
">",
"queryParamMap",
",",
"Object",
"data",
")",
"throw... | Executes POST method for given request parameters.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param headerMap Map of HTTP headers for the request.
@param queryParamMap Map of HTTP query parameters of the request.
@param data HTTP request body data. | [
"Executes",
"POST",
"method",
"for",
"given",
"request",
"parameters",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1363-L1369 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getObjectUrl | public String getObjectUrl(String bucketName, String objectName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
Request request = createRequest(Method.GET, bucketName, objectName, getRegion(bucketName),
null, null, null, null, 0);
HttpUrl url = request.url();
return url.toString();
} | java | public String getObjectUrl(String bucketName, String objectName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
Request request = createRequest(Method.GET, bucketName, objectName, getRegion(bucketName),
null, null, null, null, 0);
HttpUrl url = request.url();
return url.toString();
} | [
"public",
"String",
"getObjectUrl",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseExce... | Gets object's URL in given bucket. The URL is ONLY useful to retrieve the object's data if the object has
public read permissions.
<p><b>Example:</b>
<pre>{@code String url = minioClient.getObjectUrl("my-bucketname", "my-objectname");
System.out.println(url); }</pre>
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@return string contains URL to download the object.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Gets",
"object",
"s",
"URL",
"in",
"given",
"bucket",
".",
"The",
"URL",
"is",
"ONLY",
"useful",
"to",
"retrieve",
"the",
"object",
"s",
"data",
"if",
"the",
"object",
"has",
"public",
"read",
"permissions",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L1560-L1568 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.copyObject | public void copyObject(String bucketName, String objectName, String destBucketName)
throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException,
NoResponseException, ErrorResponseException, InternalException, IOException, XmlPullParserException,
InvalidArgumentException {
copyObject(bucketName, objectName, destBucketName, null, null, null);
} | java | public void copyObject(String bucketName, String objectName, String destBucketName)
throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException,
NoResponseException, ErrorResponseException, InternalException, IOException, XmlPullParserException,
InvalidArgumentException {
copyObject(bucketName, objectName, destBucketName, null, null, null);
} | [
"public",
"void",
"copyObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"String",
"destBucketName",
")",
"throws",
"InvalidKeyException",
",",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"NoR... | Copy a source object into a new destination object with same object name.
</p>
<b>Example:</b><br>
<pre>
{@code minioClient.copyObject("my-bucketname", "my-objectname", "my-destbucketname");}
</pre>
@param bucketName
Bucket name where the object to be copied exists.
@param objectName
Object name source to be copied.
@param destBucketName
Bucket name where the object will be copied to.
@throws InvalidKeyException
upon an invalid access key or secret key
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws NoResponseException upon no response from server
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws IOException upon connection error
@throws XmlPullParserException upon parsing response xml
@throws InvalidArgumentException upon invalid value is passed to a method. | [
"Copy",
"a",
"source",
"object",
"into",
"a",
"new",
"destination",
"object",
"with",
"same",
"object",
"name",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2008-L2014 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getPresignedObjectUrl | public String getPresignedObjectUrl(Method method, String bucketName, String objectName, Integer expires,
Map<String, String> reqParams)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
// Validate input.
if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
throw new InvalidExpiresRangeException(expires, "expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
}
byte[] body = null;
if (method == Method.PUT || method == Method.POST) {
body = new byte[0];
}
Multimap<String, String> queryParamMap = null;
if (reqParams != null) {
queryParamMap = HashMultimap.create();
for (Map.Entry<String, String> m: reqParams.entrySet()) {
queryParamMap.put(m.getKey(), m.getValue());
}
}
String region = getRegion(bucketName);
Request request = createRequest(method, bucketName, objectName, region, null, queryParamMap, null, body, 0);
HttpUrl url = Signer.presignV4(request, region, accessKey, secretKey, expires);
return url.toString();
} | java | public String getPresignedObjectUrl(Method method, String bucketName, String objectName, Integer expires,
Map<String, String> reqParams)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
// Validate input.
if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
throw new InvalidExpiresRangeException(expires, "expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
}
byte[] body = null;
if (method == Method.PUT || method == Method.POST) {
body = new byte[0];
}
Multimap<String, String> queryParamMap = null;
if (reqParams != null) {
queryParamMap = HashMultimap.create();
for (Map.Entry<String, String> m: reqParams.entrySet()) {
queryParamMap.put(m.getKey(), m.getValue());
}
}
String region = getRegion(bucketName);
Request request = createRequest(method, bucketName, objectName, region, null, queryParamMap, null, body, 0);
HttpUrl url = Signer.presignV4(request, region, accessKey, secretKey, expires);
return url.toString();
} | [
"public",
"String",
"getPresignedObjectUrl",
"(",
"Method",
"method",
",",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Integer",
"expires",
",",
"Map",
"<",
"String",
",",
"String",
">",
"reqParams",
")",
"throws",
"InvalidBucketNameException",
",",... | Returns a presigned URL string with given HTTP method, expiry time and custom request params for a specific object
in the bucket.
</p><b>Example:</b><br>
<pre>{@code String url = minioClient.getPresignedObjectUrl(Method.DELETE, "my-bucketname", "my-objectname",
60 * 60 * 24, reqParams);
System.out.println(url); }</pre>
@param method HTTP {@link Method}.
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param expires Expiration time in seconds of presigned URL.
@param reqParams Override values for set of response headers. Currently supported request parameters are
[response-expires, response-content-type, response-cache-control, response-content-disposition]
@return string contains URL to download the object.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InvalidExpiresRangeException upon input expires is out of range | [
"Returns",
"a",
"presigned",
"URL",
"string",
"with",
"given",
"HTTP",
"method",
"expiry",
"time",
"and",
"custom",
"request",
"params",
"for",
"a",
"specific",
"object",
"in",
"the",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2343-L2370 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.presignedGetObject | public String presignedGetObject(String bucketName, String objectName, Integer expires,
Map<String, String> reqParams)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return getPresignedObjectUrl(Method.GET, bucketName, objectName, expires, reqParams);
} | java | public String presignedGetObject(String bucketName, String objectName, Integer expires,
Map<String, String> reqParams)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return getPresignedObjectUrl(Method.GET, bucketName, objectName, expires, reqParams);
} | [
"public",
"String",
"presignedGetObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Integer",
"expires",
",",
"Map",
"<",
"String",
",",
"String",
">",
"reqParams",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
"... | Returns an presigned URL to download the object in the bucket with given expiry time with custom request params.
</p><b>Example:</b><br>
<pre>{@code String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24, reqParams);
System.out.println(url); }</pre>
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param expires Expiration time in seconds of presigned URL.
@param reqParams Override values for set of response headers. Currently supported request parameters are
[response-expires, response-content-type, response-cache-control, response-content-disposition]
@return string contains URL to download the object.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InvalidExpiresRangeException upon input expires is out of range | [
"Returns",
"an",
"presigned",
"URL",
"to",
"download",
"the",
"object",
"in",
"the",
"bucket",
"with",
"given",
"expiry",
"time",
"with",
"custom",
"request",
"params",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2401-L2407 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.presignedGetObject | public String presignedGetObject(String bucketName, String objectName, Integer expires)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return presignedGetObject(bucketName, objectName, expires, null);
} | java | public String presignedGetObject(String bucketName, String objectName, Integer expires)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return presignedGetObject(bucketName, objectName, expires, null);
} | [
"public",
"String",
"presignedGetObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Integer",
"expires",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"Invalid... | Returns an presigned URL to download the object in the bucket with given expiry time.
</p><b>Example:</b><br>
<pre>{@code String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24);
System.out.println(url); }</pre>
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@param expires Expiration time in seconds of presigned URL.
@return string contains URL to download the object.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InvalidExpiresRangeException upon input expires is out of range | [
"Returns",
"an",
"presigned",
"URL",
"to",
"download",
"the",
"object",
"in",
"the",
"bucket",
"with",
"given",
"expiry",
"time",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2436-L2441 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.presignedPutObject | public String presignedPutObject(String bucketName, String objectName, Integer expires)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return getPresignedObjectUrl(Method.PUT, bucketName, objectName, expires, null);
} | java | public String presignedPutObject(String bucketName, String objectName, Integer expires)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidExpiresRangeException {
return getPresignedObjectUrl(Method.PUT, bucketName, objectName, expires, null);
} | [
"public",
"String",
"presignedPutObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Integer",
"expires",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"Invalid... | Returns a presigned URL to upload an object in the bucket with given expiry time.
</p><b>Example:</b><br>
<pre>{@code String url = minioClient.presignedPutObject("my-bucketname", "my-objectname", 60 * 60 * 24);
System.out.println(url); }</pre>
@param bucketName Bucket name
@param objectName Object name in the bucket
@param expires Expiration time in seconds to presigned URL.
@return string contains URL to upload the object.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InvalidExpiresRangeException upon input expires is out of range | [
"Returns",
"a",
"presigned",
"URL",
"to",
"upload",
"an",
"object",
"in",
"the",
"bucket",
"with",
"given",
"expiry",
"time",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2506-L2511 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.removeObject | public void removeObject(String bucketName, String objectName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidArgumentException {
if ((bucketName == null) || (bucketName.isEmpty())) {
throw new InvalidArgumentException("bucket name cannot be empty");
}
if ((objectName == null) || (objectName.isEmpty())) {
throw new InvalidArgumentException("object name cannot be empty");
}
executeDelete(bucketName, objectName, null);
} | java | public void removeObject(String bucketName, String objectName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidArgumentException {
if ((bucketName == null) || (bucketName.isEmpty())) {
throw new InvalidArgumentException("bucket name cannot be empty");
}
if ((objectName == null) || (objectName.isEmpty())) {
throw new InvalidArgumentException("object name cannot be empty");
}
executeDelete(bucketName, objectName, null);
} | [
"public",
"void",
"removeObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseExcept... | Removes an object from a bucket.
</p><b>Example:</b><br>
<pre>{@code minioClient.removeObject("my-bucketname", "my-objectname"); }</pre>
@param bucketName Bucket name.
@param objectName Object name in the bucket.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InvalidArgumentException upon invalid value is passed to a method. | [
"Removes",
"an",
"object",
"from",
"a",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2615-L2628 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.listObjects | public Iterable<Result<Item>> listObjects(final String bucketName) throws XmlPullParserException {
return listObjects(bucketName, null);
} | java | public Iterable<Result<Item>> listObjects(final String bucketName) throws XmlPullParserException {
return listObjects(bucketName, null);
} | [
"public",
"Iterable",
"<",
"Result",
"<",
"Item",
">",
">",
"listObjects",
"(",
"final",
"String",
"bucketName",
")",
"throws",
"XmlPullParserException",
"{",
"return",
"listObjects",
"(",
"bucketName",
",",
"null",
")",
";",
"}"
] | Lists object information in given bucket.
@param bucketName Bucket name.
@return an iterator of Result Items.
* @throws XmlPullParserException upon parsing response xml | [
"Lists",
"object",
"information",
"in",
"given",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2797-L2799 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.listObjects | public Iterable<Result<Item>> listObjects(final String bucketName, final String prefix)
throws XmlPullParserException {
// list all objects recursively
return listObjects(bucketName, prefix, true);
} | java | public Iterable<Result<Item>> listObjects(final String bucketName, final String prefix)
throws XmlPullParserException {
// list all objects recursively
return listObjects(bucketName, prefix, true);
} | [
"public",
"Iterable",
"<",
"Result",
"<",
"Item",
">",
">",
"listObjects",
"(",
"final",
"String",
"bucketName",
",",
"final",
"String",
"prefix",
")",
"throws",
"XmlPullParserException",
"{",
"// list all objects recursively",
"return",
"listObjects",
"(",
"bucketN... | Lists object information in given bucket and prefix.
@param bucketName Bucket name.
@param prefix Prefix string. List objects whose name starts with `prefix`.
@return an iterator of Result Items.
@throws XmlPullParserException upon parsing response xml | [
"Lists",
"object",
"information",
"in",
"given",
"bucket",
"and",
"prefix",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L2812-L2816 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.listBuckets | public List<Bucket> listBuckets()
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = executeGet(null, null, null, null);
ListAllMyBucketsResult result = new ListAllMyBucketsResult();
result.parseXml(response.body().charStream());
response.body().close();
return result.buckets();
} | java | public List<Bucket> listBuckets()
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = executeGet(null, null, null, null);
ListAllMyBucketsResult result = new ListAllMyBucketsResult();
result.parseXml(response.body().charStream());
response.body().close();
return result.buckets();
} | [
"public",
"List",
"<",
"Bucket",
">",
"listBuckets",
"(",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullParserException... | Returns all bucket information owned by the current user.
</p><b>Example:</b><br>
<pre>{@code List<Bucket> bucketList = minioClient.listBuckets();
for (Bucket bucket : bucketList) {
System.out.println(bucket.creationDate() + ", " + bucket.name());
} }</pre>
@return List of bucket type.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Returns",
"all",
"bucket",
"information",
"owned",
"by",
"the",
"current",
"user",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L3241-L3250 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.bucketExists | public boolean bucketExists(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
try {
executeHead(bucketName, null);
return true;
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_BUCKET) {
throw e;
}
}
return false;
} | java | public boolean bucketExists(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
try {
executeHead(bucketName, null);
return true;
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_BUCKET) {
throw e;
}
}
return false;
} | [
"public",
"boolean",
"bucketExists",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullParserExc... | Checks if given bucket exist and is having read access.
</p><b>Example:</b><br>
<pre>{@code boolean found = minioClient.bucketExists("my-bucketname");
if (found) {
System.out.println("my-bucketname exists");
} else {
System.out.println("my-bucketname does not exist");
} }</pre>
@param bucketName Bucket name.
@return True if the bucket exists and the user has at least read access.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Checks",
"if",
"given",
"bucket",
"exist",
"and",
"is",
"having",
"read",
"access",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L3281-L3295 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.makeBucket | public void makeBucket(String bucketName)
throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException,
IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
this.makeBucket(bucketName, null);
} | java | public void makeBucket(String bucketName)
throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException,
IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
this.makeBucket(bucketName, null);
} | [
"public",
"void",
"makeBucket",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"RegionConflictException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseExcepti... | Creates a bucket with default region.
@param bucketName Bucket name.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution.
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InsufficientDataException upon getting EOFException while reading given | [
"Creates",
"a",
"bucket",
"with",
"default",
"region",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L3316-L3321 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.makeBucket | public void makeBucket(String bucketName, String region)
throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException,
IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
// If region param is not provided, set it with the one provided by constructor
if (region == null) {
region = this.region;
}
// If constructor already sets a region, check if it is equal to region param if provided
if (this.region != null && !this.region.equals(region)) {
throw new RegionConflictException("passed region conflicts with the one previously specified");
}
String configString;
if (region == null || US_EAST_1.equals(region)) {
// for 'us-east-1', location constraint is not required. for more info
// http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
region = US_EAST_1;
configString = "";
} else {
CreateBucketConfiguration config = new CreateBucketConfiguration(region);
configString = config.toString();
}
HttpResponse response = executePut(bucketName, null, null, null, region, configString, 0);
response.body().close();
} | java | public void makeBucket(String bucketName, String region)
throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException,
IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
// If region param is not provided, set it with the one provided by constructor
if (region == null) {
region = this.region;
}
// If constructor already sets a region, check if it is equal to region param if provided
if (this.region != null && !this.region.equals(region)) {
throw new RegionConflictException("passed region conflicts with the one previously specified");
}
String configString;
if (region == null || US_EAST_1.equals(region)) {
// for 'us-east-1', location constraint is not required. for more info
// http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
region = US_EAST_1;
configString = "";
} else {
CreateBucketConfiguration config = new CreateBucketConfiguration(region);
configString = config.toString();
}
HttpResponse response = executePut(bucketName, null, null, null, region, configString, 0);
response.body().close();
} | [
"public",
"void",
"makeBucket",
"(",
"String",
"bucketName",
",",
"String",
"region",
")",
"throws",
"InvalidBucketNameException",
",",
"RegionConflictException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyExceptio... | Creates a bucket with given region.
</p><b>Example:</b><br>
<pre>{@code minioClient.makeBucket("my-bucketname");
System.out.println("my-bucketname is created successfully"); }</pre>
@param bucketName Bucket name.
@param region region in which the bucket will be created.
@throws InvalidBucketNameException upon invalid bucket name is given
@throws RegionConflictException upon passed region conflicts with the one
previously specified.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws InsufficientDataException upon getting EOFException while reading given | [
"Creates",
"a",
"bucket",
"with",
"given",
"region",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L3349-L3374 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.putObject | private String putObject(String bucketName, String objectName, int length,
Object data, String uploadId, int partNumber, Map<String, String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = null;
Map<String,String> queryParamMap = null;
if (partNumber > 0 && uploadId != null && !"".equals(uploadId)) {
queryParamMap = new HashMap<>();
queryParamMap.put("partNumber", Integer.toString(partNumber));
queryParamMap.put(UPLOAD_ID, uploadId);
}
response = executePut(bucketName, objectName, headerMap, queryParamMap, data, length);
response.body().close();
return response.header().etag();
} | java | private String putObject(String bucketName, String objectName, int length,
Object data, String uploadId, int partNumber, Map<String, String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
HttpResponse response = null;
Map<String,String> queryParamMap = null;
if (partNumber > 0 && uploadId != null && !"".equals(uploadId)) {
queryParamMap = new HashMap<>();
queryParamMap.put("partNumber", Integer.toString(partNumber));
queryParamMap.put(UPLOAD_ID, uploadId);
}
response = executePut(bucketName, objectName, headerMap, queryParamMap, data, length);
response.body().close();
return response.header().etag();
} | [
"private",
"String",
"putObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"int",
"length",
",",
"Object",
"data",
",",
"String",
"uploadId",
",",
"int",
"partNumber",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
")",
"... | Executes put object and returns ETag of the object.
@param bucketName
Bucket name.
@param objectName
Object name in the bucket.
@param length
Length of object data.
@param data
Object data.
@param uploadId
Upload ID of multipart put object.
@param partNumber
Part number of multipart put object. | [
"Executes",
"put",
"object",
"and",
"returns",
"ETag",
"of",
"the",
"object",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L3985-L4004 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.putObject | private void putObject(String bucketName, String objectName, Long size, Object data,
Map<String, String> headerMap, ServerSideEncryption sse)
throws InvalidBucketNameException, NoSuchAlgorithmException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException,
InvalidArgumentException, InsufficientDataException {
boolean unknownSize = false;
// Add content type if not already set
if (headerMap.get("Content-Type") == null) {
headerMap.put("Content-Type", "application/octet-stream");
}
if (size == null) {
unknownSize = true;
size = MAX_OBJECT_SIZE;
}
if (size <= MIN_MULTIPART_SIZE) {
// Single put object.
if (sse != null) {
sse.marshal(headerMap);
}
putObject(bucketName, objectName, size.intValue(), data, null, 0, headerMap);
return;
}
/* Multipart upload */
int[] rv = calculateMultipartSize(size);
int partSize = rv[0];
int partCount = rv[1];
int lastPartSize = rv[2];
Part[] totalParts = new Part[partCount];
// if sse is requested set the necessary headers before we begin the multipart session.
if (sse != null) {
sse.marshal(headerMap);
}
// initiate new multipart upload.
String uploadId = initMultipartUpload(bucketName, objectName, headerMap);
try {
int expectedReadSize = partSize;
for (int partNumber = 1; partNumber <= partCount; partNumber++) {
if (partNumber == partCount) {
expectedReadSize = lastPartSize;
}
// For unknown sized stream, check available size.
int availableSize = 0;
if (unknownSize) {
// Check whether data is available one byte more than expectedReadSize.
availableSize = getAvailableSize(data, expectedReadSize + 1);
// If availableSize is less or equal to expectedReadSize, then we reached last part.
if (availableSize <= expectedReadSize) {
// If it is first part, do single put object.
if (partNumber == 1) {
putObject(bucketName, objectName, availableSize, data, null, 0, headerMap);
return;
}
expectedReadSize = availableSize;
partCount = partNumber;
}
}
// In multi-part uploads, Set encryption headers in the case of SSE-C.
Map<String, String> encryptionHeaders = new HashMap<>();
if (sse != null && sse.getType() == ServerSideEncryption.Type.SSE_C) {
sse.marshal(encryptionHeaders);
}
String etag = putObject(bucketName, objectName, expectedReadSize, data,
uploadId, partNumber, encryptionHeaders);
totalParts[partNumber - 1] = new Part(partNumber, etag);
}
// All parts have been uploaded, complete the multipart upload.
completeMultipart(bucketName, objectName, uploadId, totalParts);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
abortMultipartUpload(bucketName, objectName, uploadId);
throw e;
}
} | java | private void putObject(String bucketName, String objectName, Long size, Object data,
Map<String, String> headerMap, ServerSideEncryption sse)
throws InvalidBucketNameException, NoSuchAlgorithmException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException,
InvalidArgumentException, InsufficientDataException {
boolean unknownSize = false;
// Add content type if not already set
if (headerMap.get("Content-Type") == null) {
headerMap.put("Content-Type", "application/octet-stream");
}
if (size == null) {
unknownSize = true;
size = MAX_OBJECT_SIZE;
}
if (size <= MIN_MULTIPART_SIZE) {
// Single put object.
if (sse != null) {
sse.marshal(headerMap);
}
putObject(bucketName, objectName, size.intValue(), data, null, 0, headerMap);
return;
}
/* Multipart upload */
int[] rv = calculateMultipartSize(size);
int partSize = rv[0];
int partCount = rv[1];
int lastPartSize = rv[2];
Part[] totalParts = new Part[partCount];
// if sse is requested set the necessary headers before we begin the multipart session.
if (sse != null) {
sse.marshal(headerMap);
}
// initiate new multipart upload.
String uploadId = initMultipartUpload(bucketName, objectName, headerMap);
try {
int expectedReadSize = partSize;
for (int partNumber = 1; partNumber <= partCount; partNumber++) {
if (partNumber == partCount) {
expectedReadSize = lastPartSize;
}
// For unknown sized stream, check available size.
int availableSize = 0;
if (unknownSize) {
// Check whether data is available one byte more than expectedReadSize.
availableSize = getAvailableSize(data, expectedReadSize + 1);
// If availableSize is less or equal to expectedReadSize, then we reached last part.
if (availableSize <= expectedReadSize) {
// If it is first part, do single put object.
if (partNumber == 1) {
putObject(bucketName, objectName, availableSize, data, null, 0, headerMap);
return;
}
expectedReadSize = availableSize;
partCount = partNumber;
}
}
// In multi-part uploads, Set encryption headers in the case of SSE-C.
Map<String, String> encryptionHeaders = new HashMap<>();
if (sse != null && sse.getType() == ServerSideEncryption.Type.SSE_C) {
sse.marshal(encryptionHeaders);
}
String etag = putObject(bucketName, objectName, expectedReadSize, data,
uploadId, partNumber, encryptionHeaders);
totalParts[partNumber - 1] = new Part(partNumber, etag);
}
// All parts have been uploaded, complete the multipart upload.
completeMultipart(bucketName, objectName, uploadId, totalParts);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
abortMultipartUpload(bucketName, objectName, uploadId);
throw e;
}
} | [
"private",
"void",
"putObject",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Long",
"size",
",",
"Object",
"data",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
",",
"ServerSideEncryption",
"sse",
")",
"throws",
"InvalidBucketN... | Executes put object. If size of object data is <= 5MiB, single put object is used
else multipart put object is used.
@param bucketName
Bucket name.
@param objectName
Object name in the bucket.
@param size
Size of object data.
@param data
Object data. | [
"Executes",
"put",
"object",
".",
"If",
"size",
"of",
"object",
"data",
"is",
"<",
"=",
"5MiB",
"single",
"put",
"object",
"is",
"used",
"else",
"multipart",
"put",
"object",
"is",
"used",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4020-L4104 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getBucketPolicy | public String getBucketPolicy(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException, BucketPolicyTooLargeException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
HttpResponse response = null;
byte[] buf = new byte[MAX_BUCKET_POLICY_SIZE];
int bytesRead = 0;
try {
response = executeGet(bucketName, null, null, queryParamMap);
bytesRead = response.body().byteStream().read(buf, 0, MAX_BUCKET_POLICY_SIZE);
if (bytesRead < 0) {
// reached EOF
throw new IOException("reached EOF when reading bucket policy");
}
// Read one byte extra to ensure only MAX_BUCKET_POLICY_SIZE data is sent by the server.
if (bytesRead == MAX_BUCKET_POLICY_SIZE) {
int byteRead = 0;
while (byteRead == 0) {
byteRead = response.body().byteStream().read();
if (byteRead < 0) {
// reached EOF which is fine.
break;
} else if (byteRead > 0) {
throw new BucketPolicyTooLargeException(bucketName);
}
}
}
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_BUCKET_POLICY) {
throw e;
}
} finally {
if (response != null && response.body() != null) {
response.body().close();
}
}
return new String(buf, 0, bytesRead, StandardCharsets.UTF_8);
} | java | public String getBucketPolicy(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException, BucketPolicyTooLargeException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
HttpResponse response = null;
byte[] buf = new byte[MAX_BUCKET_POLICY_SIZE];
int bytesRead = 0;
try {
response = executeGet(bucketName, null, null, queryParamMap);
bytesRead = response.body().byteStream().read(buf, 0, MAX_BUCKET_POLICY_SIZE);
if (bytesRead < 0) {
// reached EOF
throw new IOException("reached EOF when reading bucket policy");
}
// Read one byte extra to ensure only MAX_BUCKET_POLICY_SIZE data is sent by the server.
if (bytesRead == MAX_BUCKET_POLICY_SIZE) {
int byteRead = 0;
while (byteRead == 0) {
byteRead = response.body().byteStream().read();
if (byteRead < 0) {
// reached EOF which is fine.
break;
} else if (byteRead > 0) {
throw new BucketPolicyTooLargeException(bucketName);
}
}
}
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_BUCKET_POLICY) {
throw e;
}
} finally {
if (response != null && response.body() != null) {
response.body().close();
}
}
return new String(buf, 0, bytesRead, StandardCharsets.UTF_8);
} | [
"public",
"String",
"getBucketPolicy",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"InvalidObjectPrefixException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoRes... | Get JSON string of bucket policy of the given bucket.
@param bucketName the name of the bucket for which policies are to be listed.
</p><b>Example:</b><br>
<pre>{@code
String policyString = minioClient.getBucketPolicy("my-bucketname");
}</pre>
@return bucket policy JSON string.
@throws InvalidBucketNameException upon an invalid bucket name
@throws IOException upon connection error
@throws InvalidKeyException upon an invalid access key or secret key
@throws NoSuchAlgorithmException upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon insufficient data
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws InternalException upon internal library error
@throws ErrorResponseException upon unsuccessful execution
@throws InvalidBucketNameException upon invalid bucket name is given
@throws InvalidObjectPrefixException upon invalid object prefix.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error
@throws BucketPolicyTooLargeException upon bucket policy too large in size | [
"Get",
"JSON",
"string",
"of",
"bucket",
"policy",
"of",
"the",
"given",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4145-L4188 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.setBucketPolicy | public void setBucketPolicy(String bucketName, String policy)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> headerMap = new HashMap<>();
headerMap.put("Content-Type", "application/json");
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
HttpResponse response = executePut(bucketName, null, headerMap, queryParamMap, policy, 0);
response.body().close();
} | java | public void setBucketPolicy(String bucketName, String policy)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> headerMap = new HashMap<>();
headerMap.put("Content-Type", "application/json");
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
HttpResponse response = executePut(bucketName, null, headerMap, queryParamMap, policy, 0);
response.body().close();
} | [
"public",
"void",
"setBucketPolicy",
"(",
"String",
"bucketName",
",",
"String",
"policy",
")",
"throws",
"InvalidBucketNameException",
",",
"InvalidObjectPrefixException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidK... | Set JSON string of policy on given bucket.
@param bucketName Bucket name.
@param policy Bucket policy JSON string.
</p><b>Example:</b><br>
<pre>{@code StringBuilder builder = new StringBuilder();
builder.append("{\n");
builder.append(" \"Statement\": [\n");
builder.append(" {\n");
builder.append(" \"Action\": [\n");
builder.append(" \"s3:GetBucketLocation\",\n");
builder.append(" \"s3:ListBucket\"\n");
builder.append(" ],\n");
builder.append(" \"Effect\": \"Allow\",\n");
builder.append(" \"Principal\": \"*\",\n");
builder.append(" \"Resource\": \"arn:aws:s3:::my-bucketname\"\n");
builder.append(" },\n");
builder.append(" {\n");
builder.append(" \"Action\": \"s3:GetObject\",\n");
builder.append(" \"Effect\": \"Allow\",\n");
builder.append(" \"Principal\": \"*\",\n");
builder.append(" \"Resource\": \"arn:aws:s3:::my-bucketname/myobject*\"\n");
builder.append(" }\n");
builder.append(" ],\n");
builder.append(" \"Version\": \"2012-10-17\"\n");
builder.append("}\n");
setBucketPolicy("my-bucketname", builder.toString()); }</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws InvalidObjectPrefixException upon invalid object prefix.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error * | [
"Set",
"JSON",
"string",
"of",
"policy",
"on",
"given",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4235-L4247 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.deleteBucketLifeCycle | public void deleteBucketLifeCycle(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("lifecycle", "");
HttpResponse response = executeDelete(bucketName, "", queryParamMap);
response.body().close();
} | java | public void deleteBucketLifeCycle(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("lifecycle", "");
HttpResponse response = executeDelete(bucketName, "", queryParamMap);
response.body().close();
} | [
"public",
"void",
"deleteBucketLifeCycle",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullPar... | Delete the LifeCycle of bucket.
@param bucketName Bucket name.
</p><b>Example:</b><br>
<pre>{@code deleteBucketLifeCycle("my-bucketname"); }</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException upon requested algorithm was not found during
signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Delete",
"the",
"LifeCycle",
"of",
"bucket",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4307-L4315 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getBucketLifeCycle | public String getBucketLifeCycle(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("lifecycle", "");
HttpResponse response = null;
String bodyContent = "";
Scanner scanner = null ;
try {
response = executeGet(bucketName, "", null, queryParamMap);
scanner = new Scanner(response.body().charStream());
// read entire body stream to string.
scanner.useDelimiter("\\A");
if (scanner.hasNext()) {
bodyContent = scanner.next();
}
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_LIFECYCLE_CONFIGURATION) {
throw e;
}
} finally {
if (response != null && response.body() != null) {
response.body().close();
}
if (scanner != null) {
scanner.close();
}
}
return bodyContent;
} | java | public String getBucketLifeCycle(String bucketName)
throws InvalidBucketNameException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("lifecycle", "");
HttpResponse response = null;
String bodyContent = "";
Scanner scanner = null ;
try {
response = executeGet(bucketName, "", null, queryParamMap);
scanner = new Scanner(response.body().charStream());
// read entire body stream to string.
scanner.useDelimiter("\\A");
if (scanner.hasNext()) {
bodyContent = scanner.next();
}
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_LIFECYCLE_CONFIGURATION) {
throw e;
}
} finally {
if (response != null && response.body() != null) {
response.body().close();
}
if (scanner != null) {
scanner.close();
}
}
return bodyContent;
} | [
"public",
"String",
"getBucketLifeCycle",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
",",
"NoResponseException",
",",
"XmlPullPars... | Get bucket life cycle configuration.
@param bucketName Bucket name.
</p><b>Example:</b><br>
<pre>{@code String bucketLifeCycle = minioClient.getBucketLifecycle("my-bucketname");
}</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws NoSuchAlgorithmException upon requested algorithm was not found during
signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Get",
"bucket",
"life",
"cycle",
"configuration",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4337-L4367 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.getBucketNotification | public NotificationConfiguration getBucketNotification(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
HttpResponse response = executeGet(bucketName, null, null, queryParamMap);
NotificationConfiguration result = new NotificationConfiguration();
try {
result.parseXml(response.body().charStream());
} finally {
response.body().close();
}
return result;
} | java | public NotificationConfiguration getBucketNotification(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
HttpResponse response = executeGet(bucketName, null, null, queryParamMap);
NotificationConfiguration result = new NotificationConfiguration();
try {
result.parseXml(response.body().charStream());
} finally {
response.body().close();
}
return result;
} | [
"public",
"NotificationConfiguration",
"getBucketNotification",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"InvalidObjectPrefixException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyEx... | Get bucket notification configuration
@param bucketName Bucket name.
</p><b>Example:</b><br>
<pre>{@code NotificationConfiguration notificationConfig = minioClient.getBucketNotification("my-bucketname");
}</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws InvalidObjectPrefixException upon invalid object prefix.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Get",
"bucket",
"notification",
"configuration"
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4393-L4409 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.setBucketNotification | public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
HttpResponse response = executePut(bucketName, null, null, queryParamMap, notificationConfiguration.toString(), 0);
response.body().close();
} | java | public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
HttpResponse response = executePut(bucketName, null, null, queryParamMap, notificationConfiguration.toString(), 0);
response.body().close();
} | [
"public",
"void",
"setBucketNotification",
"(",
"String",
"bucketName",
",",
"NotificationConfiguration",
"notificationConfiguration",
")",
"throws",
"InvalidBucketNameException",
",",
"InvalidObjectPrefixException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException"... | Set bucket notification configuration
@param bucketName Bucket name.
@param notificationConfiguration Notification configuration to be set.
</p><b>Example:</b><br>
<pre>{@code minioClient.setBucketNotification("my-bucketname", notificationConfiguration);
}</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws InvalidObjectPrefixException upon invalid object prefix.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Set",
"bucket",
"notification",
"configuration"
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4437-L4445 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.removeAllBucketNotification | public void removeAllBucketNotification(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
setBucketNotification(bucketName, notificationConfiguration);
} | java | public void removeAllBucketNotification(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
setBucketNotification(bucketName, notificationConfiguration);
} | [
"public",
"void",
"removeAllBucketNotification",
"(",
"String",
"bucketName",
")",
"throws",
"InvalidBucketNameException",
",",
"InvalidObjectPrefixException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataException",
",",
"IOException",
",",
"InvalidKeyException",
","... | Remove all bucket notification.
@param bucketName Bucket name.
</p><b>Example:</b><br>
<pre>{@code minioClient.removeAllBucketNotification("my-bucketname");
}</pre>
@throws InvalidBucketNameException upon invalid bucket name is given
@throws InvalidObjectPrefixException upon invalid object prefix.
@throws NoSuchAlgorithmException
upon requested algorithm was not found during signature calculation
@throws InsufficientDataException upon getting EOFException while reading given
InputStream even before reading given length
@throws IOException upon connection error
@throws InvalidKeyException
upon an invalid access key or secret key
@throws NoResponseException upon no response from server
@throws XmlPullParserException upon parsing response xml
@throws ErrorResponseException upon unsuccessful execution
@throws InternalException upon internal library error | [
"Remove",
"all",
"bucket",
"notification",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4472-L4478 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.listIncompleteUploads | public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix)
throws XmlPullParserException {
return listIncompleteUploads(bucketName, prefix, true, true);
} | java | public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix)
throws XmlPullParserException {
return listIncompleteUploads(bucketName, prefix, true, true);
} | [
"public",
"Iterable",
"<",
"Result",
"<",
"Upload",
">",
">",
"listIncompleteUploads",
"(",
"String",
"bucketName",
",",
"String",
"prefix",
")",
"throws",
"XmlPullParserException",
"{",
"return",
"listIncompleteUploads",
"(",
"bucketName",
",",
"prefix",
",",
"tr... | Lists incomplete uploads of objects in given bucket and prefix.
@param bucketName Bucket name.
@param prefix filters the list of uploads to include only those that start with prefix.
@return an iterator of Upload.
@throws XmlPullParserException upon parsing response xml
@see #listIncompleteUploads(String, String, boolean) | [
"Lists",
"incomplete",
"uploads",
"of",
"objects",
"in",
"given",
"bucket",
"and",
"prefix",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4503-L4506 | train |
minio/minio-java | api/src/main/java/io/minio/MinioClient.java | MinioClient.initMultipartUpload | private String initMultipartUpload(String bucketName, String objectName, Map<String, String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
// set content type if not set already
if (headerMap.get("Content-Type") == null) {
headerMap.put("Content-Type", "application/octet-stream");
}
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("uploads", "");
HttpResponse response = executePost(bucketName, objectName, headerMap, queryParamMap, "");
InitiateMultipartUploadResult result = new InitiateMultipartUploadResult();
result.parseXml(response.body().charStream());
response.body().close();
return result.uploadId();
} | java | private String initMultipartUpload(String bucketName, String objectName, Map<String, String> headerMap)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
// set content type if not set already
if (headerMap.get("Content-Type") == null) {
headerMap.put("Content-Type", "application/octet-stream");
}
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("uploads", "");
HttpResponse response = executePost(bucketName, objectName, headerMap, queryParamMap, "");
InitiateMultipartUploadResult result = new InitiateMultipartUploadResult();
result.parseXml(response.body().charStream());
response.body().close();
return result.uploadId();
} | [
"private",
"String",
"initMultipartUpload",
"(",
"String",
"bucketName",
",",
"String",
"objectName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"headerMap",
")",
"throws",
"InvalidBucketNameException",
",",
"NoSuchAlgorithmException",
",",
"InsufficientDataExceptio... | Initializes new multipart upload for given bucket name, object name and content type. | [
"Initializes",
"new",
"multipart",
"upload",
"for",
"given",
"bucket",
"name",
"object",
"name",
"and",
"content",
"type",
"."
] | b2028f56403c89ce2d5900ae813bc1314c87bc7f | https://github.com/minio/minio-java/blob/b2028f56403c89ce2d5900ae813bc1314c87bc7f/api/src/main/java/io/minio/MinioClient.java#L4722-L4740 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.