code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
@InterfaceAudience.Private
public void pullRemoteRevision(final RevisionInternal rev) {
Log.d(TAG, "%s: pullRemoteRevision with rev: %s", this, rev);
++httpConnectionCount;
// Construct a query. We want the revision history, and the bodies of attachments that have
// been added si... | java |
@InterfaceAudience.Private
protected void queueRemoteRevision(RevisionInternal rev) {
if (rev.isDeleted()) {
deletedRevsToPull.add(rev);
} else {
revsToPull.add(rev);
}
} | java |
private static boolean isAllowed(char c, String allow) {
return (c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z')
|| (c >= '0' && c <= '9')
|| "_-!.~'()*".indexOf(c) != NOT_FOUND
|| (allow != null && allow.indexOf(c) != NOT_FOUND);
} | java |
public boolean mutateAttachments(CollectionUtils.Functor<Map<String, Object>,
Map<String, Object>> functor) {
{
Map<String, Object> properties = getProperties();
Map<String, Object> editedProperties = null;
Map<String, Object> attachments = (Map<String, Object>) p... | java |
public void appendData(byte[] data) throws IOException, SymmetricKeyException {
if (data == null)
return;
appendData(data, 0, data.length);
} | java |
public void finish() throws IOException, SymmetricKeyException {
if (outStream != null) {
if (encryptor != null)
outStream.write(encryptor.encrypt(null));
// FileOutputStream is also closed cascadingly
outStream.close();
outStream = null;
... | java |
public void cancel() {
try {
// FileOutputStream is also closed cascadingly
if (outStream != null) {
outStream.close();
outStream = null;
}
// Clear encryptor:
encryptor = null;
} catch (IOException e) {
... | java |
public boolean install() {
if (tempFile == null)
return true; // already installed
// Move temp file to correct location in blob store:
String destPath = store.getRawPathForKey(blobKey);
File destPathFile = new File(destPath);
if (tempFile.renameTo(destPathFile))
... | java |
@Override
@InterfaceAudience.Public
public QueryRow next() {
if (nextRow >= rows.size()) {
return null;
}
return rows.get(nextRow++);
} | java |
Map<String, Object> getProperties() {
// This is basically the inverse of -[CBLManager parseReplicatorProperties:...]
Map<String, Object> props = new HashMap<String, Object>();
props.put("continuous", isContinuous());
props.put("create_target", shouldCreateTarget());
props.put("f... | java |
@InterfaceAudience.Public
public void start() {
if (replicationInternal == null) {
initReplicationInternal();
} else {
if (replicationInternal.stateMachine.isInState(ReplicationState.INITIAL)) {
// great, it's ready to be started, nothing to do
} e... | java |
@InterfaceAudience.Public
public void setContinuous(boolean isContinous) {
if (isContinous) {
this.lifecycle = Lifecycle.CONTINUOUS;
replicationInternal.setLifecycle(Lifecycle.CONTINUOUS);
} else {
this.lifecycle = Lifecycle.ONESHOT;
replicationInterna... | java |
@InterfaceAudience.Public
public void setAuthenticator(Authenticator authenticator) {
properties.put(ReplicationField.AUTHENTICATOR, authenticator);
replicationInternal.setAuthenticator(authenticator);
} | java |
@InterfaceAudience.Public
public void setCreateTarget(boolean createTarget) {
properties.put(ReplicationField.CREATE_TARGET, createTarget);
replicationInternal.setCreateTarget(createTarget);
} | java |
@Override
public void changed(ChangeEvent event) {
// forget cached IDs (Should be executed in workExecutor)
final long lastSeqPushed = (isPull() || replicationInternal.lastSequence == null) ? -1L :
Long.valueOf(replicationInternal.lastSequence);
if (lastSeqPushed >= 0 && las... | java |
@InterfaceAudience.Public
public void setFilter(String filterName) {
properties.put(ReplicationField.FILTER_NAME, filterName);
replicationInternal.setFilter(filterName);
} | java |
@InterfaceAudience.Public
public void setDocIds(List<String> docIds) {
properties.put(ReplicationField.DOC_IDS, docIds);
replicationInternal.setDocIds(docIds);
} | java |
public void setFilterParams(Map<String, Object> filterParams) {
properties.put(ReplicationField.FILTER_PARAMS, filterParams);
replicationInternal.setFilterParams(filterParams);
} | java |
@InterfaceAudience.Public
public void setChannels(List<String> channels) {
properties.put(ReplicationField.CHANNELS, channels);
replicationInternal.setChannels(channels);
} | java |
private void initWithKey(byte[] key) throws SymmetricKeyException {
if (key == null)
throw new SymmetricKeyException("Key cannot be null");
if (key.length != KEY_SIZE)
throw new SymmetricKeyException("Key size is not " + KEY_SIZE + "bytes");
keyData = key;
} | java |
public byte[] encryptData(byte[] data) throws SymmetricKeyException {
Encryptor encryptor = createEncryptor();
byte[] encrypted = encryptor.encrypt(data);
byte[] trailer = encryptor.encrypt(null);
if (encrypted == null || trailer == null)
throw new SymmetricKeyException("Cann... | java |
private static byte[] generateKey(int size) throws SymmetricKeyException {
if (size <= 0)
throw new IllegalArgumentException("Size cannot be zero or less than zero.");
try {
SecureRandom secureRandom = new SecureRandom();
KeyGenerator keyGenerator = KeyGenerator.getI... | java |
private static byte[] secureRandom(int size) {
if (size <= 0)
throw new IllegalArgumentException("Size cannot be zero or less than zero.");
SecureRandom secureRandom = new SecureRandom();
byte[] bytes = new byte[size];
secureRandom.nextBytes(bytes);
return bytes;
... | java |
private Cipher getCipher(int mode, byte[] iv) throws SymmetricKeyException {
Cipher cipher = null;
try {
cipher = getCipherInstance("AES/CBC/PKCS7Padding");
if (cipher == null) {
throw new SymmetricKeyException("Cannot get a cipher instance for AES/CBC/PKCS7Paddin... | java |
private Cipher getCipherInstance(String algorithm) {
Cipher cipher = null;
if (!useBCProvider) {
try {
cipher = Cipher.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
Log.v(Log.TAG_SYMMETRIC_KEY, "Cannot find a cipher (no algorithm)... | java |
public synchronized long addValue(String value) {
sequences.add(++lastSequence);
values.add(value);
return lastSequence;
} | java |
public synchronized long getCheckpointedSequence() {
long sequence = lastSequence;
if(!sequences.isEmpty()) {
sequence = sequences.first() - 1;
}
if(sequence > firstValueSequence) {
// Garbage-collect inaccessible values:
int numToRemove = (int)(sequence - firstValueSequence);
for(int i = 0; i < ... | java |
public synchronized String getCheckpointedValue() {
int index = (int)(getCheckpointedSequence() - firstValueSequence);
return (index >= 0) ? values.get(index) : null;
} | java |
public static void serialize(Serializable obj, ByteArrayOutputStream bout) {
try {
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(obj);
out.close();
} catch (IOException e) {
throw new IllegalStateException("Could not serialize " + obj, e);
}
} | java |
public static List<String> readToList(File f) throws IOException {
try (final Reader reader = asReaderUTF8Lenient(new FileInputStream(f))) {
return readToList(reader);
} catch (IOException ioe) {
throw new IllegalStateException(String.format("Failed to read %s: %s", f.getAbsolutePath(), ioe), ioe);
}
} | java |
public static List<String> readToList(Reader r) throws IOException {
try ( BufferedReader in = new BufferedReader(r) ) {
List<String> l = new ArrayList<>();
String line = null;
while ((line = in.readLine()) != null)
l.add(line);
return Collections.unmodifiableList(l);
}
} | java |
public static String readFileToString(File f) throws IOException {
StringWriter sw = new StringWriter();
IO.copyAndCloseBoth(Common.asReaderUTF8Lenient(new FileInputStream(f)), sw);
return sw.toString();
} | java |
public void appendToLog(String logAppendMessage) {
ProfilingTimerNode currentNode = current.get();
if (currentNode != null) {
currentNode.appendToLog(logAppendMessage);
}
} | java |
public void mergeTree(ProfilingTimerNode otherRoot) {
ProfilingTimerNode currentNode = current.get();
Preconditions.checkNotNull(currentNode);
mergeOrAddNode(currentNode, otherRoot);
} | java |
private static void writeToLog(int level, long totalNanos, long count, ProfilingTimerNode parent, String taskName, Log log, String logAppendMessage) {
if (log == null) {
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < level; i++) {
sb.append('\t');
}
String durationText = String... | java |
public static <T extends TBase> String serializeJson(T obj) throws TException {
// Tried having a static final serializer, but it doesn't seem to be thread safe
return new TSerializer(new TJSONProtocol.Factory()).toString(obj, THRIFT_CHARSET);
} | java |
public static <T extends TBase> T deserializeJson(T dest, String thriftJson) throws TException {
// Tried having a static final deserializer, but it doesn't seem to be thread safe
new TDeserializer(new TJSONProtocol.Factory()).deserialize(dest, thriftJson, THRIFT_CHARSET);
return dest;
} | java |
public static String sepList(String sep, Iterable<?> os, int max) {
return sepList(sep, null, os, max);
} | java |
Word2VecModel train(Log log, TrainingProgressListener listener, Iterable<List<String>> sentences) throws InterruptedException {
try (ProfilingTimer timer = ProfilingTimer.createLoggingSubtasks(log, "Training word2vec")) {
final Multiset<String> counts;
try (AC ac = timer.start("Acquiring word frequencies"))... | java |
private void normalize() {
for(int i = 0; i < vocab.size(); ++i) {
double len = 0;
for(int j = i * layerSize; j < (i + 1) * layerSize; ++j)
len += vectors.get(j) * vectors.get(j);
len = Math.sqrt(len);
for(int j = i * layerSize; j < (i + 1) * layerSize; ++j)
vectors.put(j, vectors.get(j) / len);
... | java |
protected void init() throws IOException {
if (internalIn2 != null) return;
String encoding;
byte bom[] = new byte[BOM_SIZE];
int n, unread;
n = internalIn.read(bom, 0, bom.length);
if ( (bom[0] == (byte)0x00) && (bom[1] == (byte)0x00) &&
(bom[2] == (byte)0xFE) && (bom[3] == (byte)0xFF) ) {
encodin... | java |
public static File getDir(File parent, String item) {
File dir = new File(parent, item);
return (dir.exists() && dir.isDirectory()) ? dir : null;
} | java |
public static boolean deleteRecursive(final File file) {
boolean result = true;
if (file.isDirectory()) {
for (final File inner : file.listFiles()) {
result &= deleteRecursive(inner);
}
}
return result & file.delete();
} | java |
public static File createTempFile(byte[] fileContents, String namePrefix, String extension) throws IOException {
Preconditions.checkNotNull(fileContents, "file contents missing");
File tempFile = File.createTempFile(namePrefix, extension);
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write... | java |
public static void demoWord() throws IOException, TException, InterruptedException, UnknownWordException {
File f = new File("text8");
if (!f.exists())
throw new IllegalStateException("Please download and unzip the text8 example from http://mattmahoney.net/dc/text8.zip");
List<String> read = Commo... | java |
public static void loadModel() throws IOException, TException, UnknownWordException {
final Word2VecModel model;
try (ProfilingTimer timer = ProfilingTimer.create(LOG, "Loading model")) {
String json = Common.readFileToString(new File("text8.model"));
model = Word2VecModel.fromThrift(ThriftUtils.deserializeJs... | java |
public static void skipGram() throws IOException, TException, InterruptedException, UnknownWordException {
List<String> read = Common.readToList(new File("sents.cleaned.word2vec.txt"));
List<List<String>> partitioned = Lists.transform(read, new Function<String, List<String>>() {
@Override
public List<String> ... | java |
private Catalogo copy(Catalogo catalogo) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Marshaller m = context.createMarshaller();
m.marshal(... | java |
private String[] findFeatureByScenarioName(String scenarioName) throws IllegalAccessException {
List<Description> testClasses = findTestClassesLevel(parentDescription.getChildren());
for (Description testClass : testClasses) {
List<Description> features = findFeaturesLevel(testClass.getChi... | java |
Stories getStoriesAnnotation(final String[] value) {
return new Stories() {
@Override
public String[] value() {
return value;
}
@Override
public Class<Stories> annotationType() {
return Stories.class;
}
... | java |
Features getFeaturesAnnotation(final String[] value) {
return new Features() {
@Override
public String[] value() {
return value;
}
@Override
public Class<Features> annotationType() {
return Features.class;
... | java |
public <E extends Enum<E>> List<E> getTypeList(Class<E> clz, E[] typeList) {
if (typeList.length > 0) {
return new ArrayList<>(Arrays.asList(typeList));
} else {
return new ArrayList<>(EnumSet.allOf(clz));
}
} | java |
public ExternalID getPersonExternalIds(int personId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, personId);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters);
String webpage = h... | java |
public ResultList<Artwork> getPersonImages(int personId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, personId);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.IMAGES).buildUrl(parameters);
String webpage = htt... | java |
public ResultList<PersonFind> getPersonPopular(Integer page) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.POPULAR).buildUrl(parameters);
WrapperGenericLis... | java |
public List<Artwork> getAll(ArtworkType... artworkList) {
List<Artwork> artwork = new ArrayList<>();
List<ArtworkType> types;
if (artworkList.length > 0) {
types = new ArrayList<>(Arrays.asList(artworkList));
} else {
types = new ArrayList<>(Arrays.asList(Artwork... | java |
private void updateArtworkType(List<Artwork> artworkList, ArtworkType type) {
for (Artwork artwork : artworkList) {
artwork.setArtworkType(type);
}
} | java |
public TokenAuthorisation getAuthorisationToken() throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.TOKEN_NEW).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
... | java |
public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
if (!token.getSuccess()) {
throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!");
}
param... | java |
public TokenSession getGuestSessionToken() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.GUEST_SESSION).buildUrl();
String webpage = httpTools.getRequest(url);
try {
return MAPPER.readValue(webpage, TokenSession.class);
} catch (... | java |
private void initialise(String apiKey, HttpTools httpTools) {
tmdbAccount = new TmdbAccount(apiKey, httpTools);
tmdbAuth = new TmdbAuthentication(apiKey, httpTools);
tmdbCertifications = new TmdbCertifications(apiKey, httpTools);
tmdbChanges = new TmdbChanges(apiKey, httpTools);
... | java |
public ResultList<MovieBasic> getFavoriteMovies(String sessionId, int accountId) throws MovieDbException {
return tmdbAccount.getFavoriteMovies(sessionId, accountId);
} | java |
public StatusCode modifyFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException {
return tmdbAccount.modifyFavoriteStatus(sessionId, accountId, mediaType, mediaId, isFavorite);
} | java |
public ResultList<TVBasic> getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
return tmdbAccount.getWatchListTV(sessionId, accountId, page, sortBy, language);
} | java |
public StatusCode addToWatchList(String sessionId, int accountId, MediaType mediaType, Integer mediaId) throws MovieDbException {
return tmdbAccount.modifyWatchList(sessionId, accountId, mediaType, mediaId, true);
} | java |
public StatusCode removeFromWatchList(String sessionId, int accountId, MediaType mediaType, Integer mediaId) throws MovieDbException {
return tmdbAccount.modifyWatchList(sessionId, accountId, mediaType, mediaId, false);
} | java |
public ResultList<TVBasic> getFavoriteTv(String sessionId, int accountId) throws MovieDbException {
return tmdbAccount.getFavoriteTv(sessionId, accountId);
} | java |
public ResultList<ChangeListItem> getMovieChangeList(Integer page, String startDate, String endDate) throws MovieDbException {
return tmdbChanges.getChangeList(MethodBase.MOVIE, page, startDate, endDate);
} | java |
public ResultList<ChangeListItem> getTvChangeList(Integer page, String startDate, String endDate) throws MovieDbException {
return tmdbChanges.getChangeList(MethodBase.TV, page, startDate, endDate);
} | java |
public ResultList<ChangeListItem> getPersonChangeList(Integer page, String startDate, String endDate) throws MovieDbException {
return tmdbChanges.getChangeList(MethodBase.PERSON, page, startDate, endDate);
} | java |
public ResultList<MovieBasic> getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException {
return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies, includeAdult);
} | java |
public boolean checkItemStatus(String listId, Integer mediaId) throws MovieDbException {
return tmdbList.checkItemStatus(listId, mediaId);
} | java |
public StatusCode removeItemFromList(String sessionId, String listId, Integer mediaId) throws MovieDbException {
return tmdbList.removeItem(sessionId, listId, mediaId);
} | java |
public ResultList<Video> getMovieVideos(int movieId, String language) throws MovieDbException {
return tmdbMovies.getMovieVideos(movieId, language);
} | java |
public ResultList<Review> getMovieReviews(int movieId, Integer page, String language) throws MovieDbException {
return tmdbMovies.getMovieReviews(movieId, page, language);
} | java |
public ResultList<UserList> getMovieLists(int movieId, Integer page, String language) throws MovieDbException {
return tmdbMovies.getMovieLists(movieId, page, language);
} | java |
public ResultList<MovieInfo> getTopRatedMovies(Integer page, String language) throws MovieDbException {
return tmdbMovies.getTopRatedMovies(page, language);
} | java |
public PersonCreditList<CreditTVBasic> getPersonTVCredits(int personId, String language) throws MovieDbException {
return tmdbPeople.getPersonTVCredits(personId, language);
} | java |
public ResultList<ChangeKeyItem> getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException {
return tmdbPeople.getPersonChanges(personId, startDate, endDate);
} | java |
public ResultList<Keyword> searchKeyword(String query, Integer page) throws MovieDbException {
return tmdbSearch.searchKeyword(query, page);
} | java |
public MediaState getTVAccountState(int tvID, String sessionID) throws MovieDbException {
return tmdbTv.getTVAccountState(tvID, sessionID);
} | java |
public ExternalID getTVExternalIDs(int tvID, String language) throws MovieDbException {
return tmdbTv.getTVExternalIDs(tvID, language);
} | java |
public StatusCode postTVRating(int tvID, int rating, String sessionID, String guestSessionID) throws MovieDbException {
return tmdbTv.postTVRating(tvID, rating, sessionID, guestSessionID);
} | java |
public ResultList<TVInfo> getTVSimilar(int tvID, Integer page, String language) throws MovieDbException {
return tmdbTv.getTVSimilar(tvID, page, language);
} | java |
public ResultList<TVInfo> getTVOnTheAir(Integer page, String language) throws MovieDbException {
return tmdbTv.getTVOnTheAir(page, language);
} | java |
public ResultList<TVInfo> getTVAiringToday(Integer page, String language, String timezone) throws MovieDbException {
return tmdbTv.getTVAiringToday(page, language, timezone);
} | java |
public ExternalID getSeasonExternalID(int tvID, int seasonNumber, String language) throws MovieDbException {
return tmdbSeasons.getSeasonExternalID(tvID, seasonNumber, language);
} | java |
public ResultList<Artwork> getSeasonImages(int tvID, int seasonNumber, String language, String... includeImageLanguage) throws MovieDbException {
return tmdbSeasons.getSeasonImages(tvID, seasonNumber, language, includeImageLanguage);
} | java |
public MediaCreditList getEpisodeCredits(int tvID, int seasonNumber, int episodeNumber) throws MovieDbException {
return tmdbEpisodes.getEpisodeCredits(tvID, seasonNumber, episodeNumber);
} | java |
public ExternalID getEpisodeExternalID(int tvID, int seasonNumber, int episodeNumber, String language) throws MovieDbException {
return tmdbEpisodes.getEpisodeExternalID(tvID, seasonNumber, episodeNumber, language);
} | java |
public ResultsMap<String, List<Certification>> getMoviesCertification() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).subMethod(MethodSub.MOVIE_LIST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
JsonNode node = MAPPER.readTree(webp... | java |
private static boolean compareTitles(String primaryTitle, String firstCompareTitle, String secondCompareTitle, int maxDistance) {
// Compare with the first title
if (compareDistance(primaryTitle, firstCompareTitle, maxDistance)) {
return true;
}
// Compare with the other tit... | java |
public static boolean movies(final MovieInfo moviedb, final String title, final String year, int maxDistance) {
return Compare.movies(moviedb, title, year, maxDistance, true);
} | java |
private static boolean compareDistance(final String title1, final String title2, int distance) {
return StringUtils.getLevenshteinDistance(title1, title2) <= distance;
} | java |
public MediaCreditList getMovieCredits(int movieId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, movieId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.CREDITS).buildUrl(parameters);
String webpage = httpTools... | java |
public ResultList<Keyword> getMovieKeywords(int movieId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, movieId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.KEYWORDS).buildUrl(parameters);
String webpage = htt... | java |
public ResultList<MovieInfo> getRecommendations(int movieId, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, movieId);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod... | java |
public ResultList<ReleaseDates> getReleaseDates(int movieId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, movieId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.RELEASE_DATES).buildUrl(parameters);
WrapperGene... | java |
public ResultList<Translation> getMovieTranslations(int movieId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, movieId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.TRANSLATIONS).buildUrl(parameters);
String w... | java |
public ResultList<ChangeKeyItem> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException {
return getMediaChanges(movieId, startDate, endDate);
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.