Reads items from the remote server
@param sync true if synchronization should be forced
@param in a stream from which user input can be read
@return an item data provider providing all items from the
remote server
424046
private ItemDataProvider connect(boolean sync, InputReader in) {
		//read app's consumer key and secret
		String[] consumer;
		try {
			consumer = readConsumer();
		} catch (Exception e) {
			//should never happen
			throw new RuntimeException("Could not read OAuth consumer key and secret");
		}
		
		//use previously stored authentication
		File authStoreFile = new File(CSLToolContext.current().getConfigDir(),
				getAuthStoreFileName());
		AuthenticationStore authStore;
		try {
			authStore = new FileAuthenticationStore(authStoreFile);
		} catch (IOException e) {
			error("could not read user's authentication store: " + authStoreFile.getPath());
			return null;
		}
		
		//connect to remote server
		RemoteConnector dmc = createRemoteConnector(consumer[0], consumer[1]);
		dmc = new AuthenticatedRemoteConnector(dmc, authStore);
		
		//enable cache
		File cacheFile = new File(CSLToolContext.current().getConfigDir(),
				getCacheFileName());
		CachingRemoteConnector mc = new CachingRemoteConnector(dmc, cacheFile);
		
		//clear cache if necessary
		if (sync) {
			mc.clear();
		}

		List<CSLItemData> itemDataList;
		int retries = 1;
		while (true) {
			try {
				//download list of item IDs
				boolean cacheempty = false;
				if (!mc.hasItemList()) {
					System.out.print("Retrieving items ...");
					cacheempty = true;
				}
				List<String> items = mc.getItemIDs();
				if (cacheempty) {
					System.out.println();
				}
				
				//download all items
				itemDataList = new ArrayList<>(items.size());
				int s = 0;
				int printed = 0;
				int bulk = mc.getMaxBulkItems();
				if (bulk == 1) {
					mc.beginTransaction();
				}
				
				while (s < items.size()) {
					int n = 0;
					List<String> itemsToRetrieve = new ArrayList<>(bulk);
					while (s < items.size() && n < bulk) {
						String did = items.get(s);
						if (!mc.containsItemId(did)) {
							String msg = String.format("\rSynchronizing (%d/%d) ...",
									s + 1, items.size());
							System.out.print(msg);
							++printed;
							++n;
						}
						itemsToRetrieve.add(did);
						++s;
					}
					Map<String, CSLItemData> itemData = mc.getItems(itemsToRetrieve);
					itemDataList.addAll(itemData.values());
					
					if (bulk == 1 && s % 10 == 0) {
						mc.commitTransaction();
					}
				}
				
				if (bulk == 1) {
					mc.commitTransaction();
					mc.endTransaction();
				}
				
				if (printed > 0) {
					System.out.println();
				}
			} catch (UnauthorizedException e) {
				if (retries == 0) {
					error("failed to authorize.");
					return null;
				}
				--retries;
				
				//app is not authenticated yet
				System.out.print("\r"); //overwrite 'Retrieving items' message
				if (!authorize(mc, in)) {
					return null;
				}
				
				continue;
			} catch (RequestException e) {
				error(e.getMessage());
				return null;
			} catch (IOException e) {
				error("could not get list of items from remote server.");
				return null;
			}
			
			break;
		}
		
		//return provider that contains all items from the server
		CSLItemData[] itemDataArr = itemDataList.toArray(new CSLItemData[itemDataList.size()]);
		return createItemDataProvider(itemDataArr);
	}
15395
public final AtomEntry<JsonObject> readAtomEntry(final InputStream in) {

        try (final JsonReader jsonReader = Json.createReader(new InputStreamReader(in))) {
            final JsonObject jsonObj = jsonReader.readObject();
            try {
            
                final String eventStreamId = ((JsonString) JsonPath.read(jsonObj, "$.content.eventStreamId")).getString();
                final int eventNumber = ((JsonNumber) JsonPath.read(jsonObj, "$.content.eventNumber")).intValue();
                final String eventType = ((JsonString) JsonPath.read(jsonObj, "$.content.eventType")).getString();
                final String eventId = ((JsonString) JsonPath.read(jsonObj, "$.content.eventId")).getString();
        
                final JsonObject escMetaObj = JsonPath.read(jsonObj, "$.content.metadata");
        
                final String dataContentTypeStr = escMetaObj.getString("data-content-type");
                final EnhancedMimeType dataContentType = EnhancedMimeType.create(dataContentTypeStr);
                final JsonObject data = JsonPath.read(jsonObj, "$.content.data");
        
                final EnhancedMimeType metaContentType;
                final String metaTypeStr;
                final JsonObject meta;
                if (escMetaObj.containsKey("meta-type")) {
                    metaTypeStr = escMetaObj.getString("meta-type");
                    final String metaContentTypeStr = escMetaObj.getString("meta-content-type");
                    metaContentType = EnhancedMimeType.create(metaContentTypeStr);
                    meta = escMetaObj;
                } else {
                    metaTypeStr = null;
                    metaContentType = null;
                    meta = null;
                }
        
                return new AtomEntry<JsonObject>(eventStreamId, eventNumber, eventType, eventId, dataContentType,
                        metaContentType, metaTypeStr, data, meta);
    
            } catch (final RuntimeException ex) {
                LOG.error("Failed to parse JSON atom feed: " + jsonObj);
                throw ex;
            }
        }
        
    }
883874
public static TermsSet readFrom(BytesRef in) {
    TermsByQueryRequest.TermsEncoding termsEncoding = TermsByQueryRequest.TermsEncoding.values()[Bytes.readInt(in)];
    switch (termsEncoding) {
      case INTEGER:
        return new IntegerTermsSet(in);
      case LONG:
        return new LongTermsSet(in);
      case BLOOM:
        return new BloomFilterTermsSet(in);
      case BYTES:
        return new BytesRefTermsSet(in);
      default:
        throw new IllegalArgumentException("[termsByQuery] Invalid terms encoding: " + termsEncoding.name());
    }
  }
51625
@Override
	public void read(final DataInput in) throws IOException {

		synchronized (this.confData) {

			final int numberOfProperties = in.readInt();

			for (int i = 0; i < numberOfProperties; i++) {
				final String key = StringRecord.readString(in);
				final String value = StringRecord.readString(in);
				this.confData.put(key, value);
			}
		}
	}
147022
public ItemImpl getItem(QPath path, boolean pool) throws RepositoryException
   {
      long start = 0;
      if (LOG.isDebugEnabled())
      {
         start = System.currentTimeMillis();
         LOG.debug("getItem(" + path.getAsString() + " ) >>>>>");
      }

      ItemImpl item = null;
      try
      {
         return item = readItem(getItemData(path), pool);
      }
      finally
      {
         if (LOG.isDebugEnabled())
         {
            LOG.debug("getItem(" + path.getAsString() + ") --> " + (item != null ? item.getPath() : "null") + " <<<<< "
               + ((System.currentTimeMillis() - start) / 1000d) + "sec");
         }
      }
   }
1232135
public T sync() {
        //if data is present there's no need to block
        if (data != null) {
            return data;
        }
        synchronized (this) {
            try {
                // wait();
                block.take();
            } catch (InterruptedException e) {
                if (interruptCause == null) {
                    interruptCause = e;
                }
            }
            if (interruptCause != null) {
                if (interruptCause instanceof DataSiftException) {
                    throw (DataSiftException) interruptCause;
                } else {
                    throw new DataSiftException("Interrupted while waiting for response", interruptCause);
                }
            }
            return data;
        }
    }
650465
public <RH extends CheckedConsumer<? super T>> RH read(final Collection<K> keys, final RH consumer) throws SQLException {
        transactionTemplate
            .doInTransaction(new SQLFunction<Connection, Object>() {
                @Override
                public Object apply(Connection connection) throws SQLException {
                    delegate.read(connection, keys, consumer);
                    return null;
                }
            });
        return consumer;
    }
420703
@Override
  public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);

    routing = in.readOptionalString();
    preference = in.readOptionalString();

    if (in.readBoolean()) {
      querySource = in.readBytesReference();
    } else {
      querySource = null;
    }

    if (in.readBoolean()) {
      types = in.readStringArray();
    }

    field = in.readString();
    nowInMillis = in.readVLong();

    if (in.readBoolean()) {
      ordering = Ordering.values()[in.readVInt()];
    }

    if (in.readBoolean()) {
      maxTermsPerShard = in.readVInt();
    }

    if (in.readBoolean()) {
      termsEncoding = TermsEncoding.values()[in.readVInt()];
    }

    if (in.readBoolean()) {
      expectedTerms = in.readVLong();
    }
  }
575460
def getMedia(self):
        
        server = self.server().connect()
        key = '/sync/items/%s' % self.id
        return server.fetchItems(key)
1198964
public static BufferedReader getReader(InputStream in, Charset charset) {
		if (null == in) {
			return null;
		}

		InputStreamReader reader = null;
		if (null == charset) {
			reader = new InputStreamReader(in);
		} else {
			reader = new InputStreamReader(in, charset);
		}

		return new BufferedReader(reader);
	}
606605
public Command readPDUHeader(DataInputStream in)
            throws InvalidCommandLengthException, IOException {
        synchronized (in) {
            return pduReader.readPDUHeader(in);
        }
    }
71918
public boolean readRequest(MuxInputStream in, MuxOutputStream out)
        throws IOException
    {
        int channel = isClient ? 3 : 2;

        in.init(this, channel);
        out.init(this, channel);

        if (readChannel(channel) != null) {
            in.setInputStream(is);
            in.readToData(false);
            return true;
        }
        else
            return false;
    }
1167173
private SynchronizationAdapter createSynchronizationAdapter(Transaction transaction) {
      SynchronizationAdapter adapter = new SynchronizationAdapter(transaction, RemoteXid.create(uuid));
      try {
         transaction.registerSynchronization(adapter);
      } catch (RollbackException | SystemException e) {
         throw new CacheException(e);
      }
      if (trace) {
         log.tracef("Registered synchronization for transaction %s. Sync=%s", transaction, adapter);
      }
      return adapter;
   }
606823
public static Reader reader(Format type, InputStream in) {
        return reader(type, in, defaultDefaultReadHandler());
    }
953289
public static Function<IHTTPSession, Response> syncHandler(final ExecutorService pool, final String mimeType, @javax.annotation.Nonnull final Consumer<OutputStream> logic, final boolean async) {
    return session -> {
      try (@javax.annotation.Nonnull ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        logic.accept(out);
        out.flush();
        final byte[] bytes = out.toByteArray();
        return NanoHTTPD.newFixedLengthResponse(Response.Status.OK, mimeType, new ByteArrayInputStream(bytes), bytes.length);
      } catch (@javax.annotation.Nonnull final IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
      }
    };
  }
334162
function syncItem ( pinboard, item ) {
	return pify(pinboard.add.bind(pinboard))(item)
		.then(( res ) => {
			if ( typeof res === 'undefined' ) {
				return Promise.reject('Unknown error occured while syncing with Pinboard.');
			}
			if ( res.result_code !== 'done' ) {
				return Promise.reject(`Error while syncing with Pinboard: ${res.result_code}`);
			}
			return {
				url: item.url,
				pinboardResponse: res
			};
		});
}
326010
public ChangeSet read(final InputSource in) throws SAXException,
                                                  IOException {
        return (ChangeSet) this.parser.read( in );
    }