Returns a {@code ByteSource} object that wraps the batch job response into chunks with
pagination, which will be parsed by Axis/JAX-WS.
320479
public ByteSource buildWrappedByteSource(URL url, int startIndex, int numberResults)
      throws IOException, XMLStreamException, TransformerException {
    Preconditions.checkArgument(startIndex >= 0, "startIndex must not be negative");
    Preconditions.checkArgument(numberResults > 0, "numberResults must be positive");

    StringWriter stringWriter = new StringWriter();

    XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(url.openStream());
    XMLEventWriter xmlEventWriter = xmlOutputFactory.createXMLEventWriter(stringWriter);

    int index = 0;
    boolean included = false;

    while (xmlEventReader.hasNext()) {
      XMLEvent event = xmlEventReader.nextEvent();

      if (event.isStartElement()) {
        String name = ((StartElement) event).getName().getLocalPart();
        if (name.equals(TAG_MUTATE_RESPONSE)) {
          // Write the <mutateResponse> tag.
          xmlEventWriter.add(event);
          continue;
        } else if (name.equals(TAG_RVAL) && ++index > startIndex) {
          // Included the eligible <rval> tags and sub tags by setting the 'included' flag.
          included = true;
        }
      } else if (event.isEndElement()) {
        String name = ((EndElement) event).getName().getLocalPart();
        if (name.equals(TAG_MUTATE_RESPONSE)) {
          // Write the </mutateResponse> tag.
          xmlEventWriter.add(event);
          break;
        } else if (included && name.equals(TAG_RVAL) && index == startIndex + numberResults) {
          // Write the last </rval> tag and append a </mutateResponse> tag, if this has written
          // the specified number of results.
          xmlEventWriter.add(event);
          xmlEventWriter.add(xmlEventFactory.createEndElement("", "", TAG_MUTATE_RESPONSE));
          break;
        }
      }

      if (included) {
        // Write the included tags and events.
        xmlEventWriter.add(event);
      }
    }
    xmlEventReader.close();
    xmlEventWriter.close();

    InputStream truncatedInputStream =
        ByteSource.wrap(stringWriter.toString().getBytes(UTF_8)).openStream();

    // Pass the input stream through a Transformer that removes the XML
    // declaration.
    Transformer transformer = transformerSupplier.get();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    StreamResult streamResult = new StreamResult(outputStream);
    Source xmlSource = new StreamSource(truncatedInputStream);
    transformer.transform(xmlSource, streamResult);

    return ByteSource.wrap(outputStream.toByteArray());
  }
680141
private List<DataSource> parsePartsCore(InputStream entityInputStream,
            String contentType) throws MessagingException, IOException {
        DataSource dataSource = new InputStreamDataSource(entityInputStream,
                contentType);
        MimeMultipart batch = new MimeMultipart(dataSource);
        MimeBodyPart batchBody = (MimeBodyPart) batch.getBodyPart(0);

        MimeMultipart changeSets = new MimeMultipart(new MimePartDataSource(
                batchBody));

        List<DataSource> result = new ArrayList<DataSource>();
        for (int i = 0; i < changeSets.getCount(); i++) {
            BodyPart part = changeSets.getBodyPart(i);

            result.add(new InputStreamDataSource(part.getInputStream(), part
                    .getContentType()));
        }
        return result;
    }
1097563
public com.google.protobuf.ByteString
      getResourceBytes() {
    java.lang.Object ref = resource_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      resource_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
260759
public ServiceCall<Batches> listBatches(ListBatchesOptions listBatchesOptions) {
    String[] pathSegments = { "v1/batches" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query("version", versionDate);
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "listBatches");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listBatchesOptions != null) {
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Batches.class));
  }
439047
public ByteBuffer asByteBuffer() {
        ByteBuffer bb = getByteBuffer();
        if (bb != null) return null;
        InputStream is = fromStreamOrUrl();
        if (is != null) return bufferFrom(is);
        String s = fromStringOrReader();
        if (s != null) return bufferFrom(s);
        throw resourceUnaccessible();
    }
126804
private Project.Resources.Resource writeResource(Resource mpx)
   {
      Project.Resources.Resource xml = m_factory.createProjectResourcesResource();
      ProjectCalendar cal = mpx.getResourceCalendar();
      if (cal != null)
      {
         xml.setCalendarUID(NumberHelper.getBigInteger(cal.getUniqueID()));
      }

      xml.setAccrueAt(mpx.getAccrueAt());
      xml.setActiveDirectoryGUID(mpx.getActiveDirectoryGUID());
      xml.setActualCost(DatatypeConverter.printCurrency(mpx.getActualCost()));
      xml.setActualOvertimeCost(DatatypeConverter.printCurrency(mpx.getActualOvertimeCost()));
      xml.setActualOvertimeWork(DatatypeConverter.printDuration(this, mpx.getActualOvertimeWork()));
      xml.setActualOvertimeWorkProtected(DatatypeConverter.printDuration(this, mpx.getActualOvertimeWorkProtected()));
      xml.setActualWork(DatatypeConverter.printDuration(this, mpx.getActualWork()));
      xml.setActualWorkProtected(DatatypeConverter.printDuration(this, mpx.getActualWorkProtected()));
      xml.setACWP(DatatypeConverter.printCurrency(mpx.getACWP()));
      xml.setAvailableFrom(mpx.getAvailableFrom());
      xml.setAvailableTo(mpx.getAvailableTo());
      xml.setBCWS(DatatypeConverter.printCurrency(mpx.getBCWS()));
      xml.setBCWP(DatatypeConverter.printCurrency(mpx.getBCWP()));
      xml.setBookingType(mpx.getBookingType());
      xml.setIsBudget(Boolean.valueOf(mpx.getBudget()));
      xml.setCanLevel(Boolean.valueOf(mpx.getCanLevel()));
      xml.setCode(mpx.getCode());
      xml.setCost(DatatypeConverter.printCurrency(mpx.getCost()));
      xml.setCostPerUse(DatatypeConverter.printCurrency(mpx.getCostPerUse()));
      xml.setCostVariance(DatatypeConverter.printCurrency(mpx.getCostVariance()));
      xml.setCreationDate(mpx.getCreationDate());
      xml.setCV(DatatypeConverter.printCurrency(mpx.getCV()));
      xml.setEmailAddress(mpx.getEmailAddress());
      xml.setFinish(mpx.getFinish());
      xml.setGroup(mpx.getGroup());
      xml.setGUID(mpx.getGUID());
      xml.setHyperlink(mpx.getHyperlink());
      xml.setHyperlinkAddress(mpx.getHyperlinkAddress());
      xml.setHyperlinkSubAddress(mpx.getHyperlinkSubAddress());
      xml.setID(NumberHelper.getBigInteger(mpx.getID()));
      xml.setInitials(mpx.getInitials());
      xml.setIsEnterprise(Boolean.valueOf(mpx.getEnterprise()));
      xml.setIsGeneric(Boolean.valueOf(mpx.getGeneric()));
      xml.setIsInactive(Boolean.valueOf(!mpx.getActive()));
      xml.setIsNull(Boolean.valueOf(mpx.getNull()));
      xml.setMaterialLabel(mpx.getMaterialLabel());
      xml.setMaxUnits(DatatypeConverter.printUnits(mpx.getMaxUnits()));
      xml.setName(mpx.getName());

      if (!mpx.getNotes().isEmpty())
      {
         xml.setNotes(mpx.getNotes());
      }

      xml.setNTAccount(mpx.getNtAccount());
      xml.setOverAllocated(Boolean.valueOf(mpx.getOverAllocated()));
      xml.setOvertimeCost(DatatypeConverter.printCurrency(mpx.getOvertimeCost()));
      xml.setOvertimeRate(DatatypeConverter.printRate(mpx.getOvertimeRate()));
      xml.setOvertimeRateFormat(DatatypeConverter.printTimeUnit(mpx.getOvertimeRateUnits()));
      xml.setOvertimeWork(DatatypeConverter.printDuration(this, mpx.getOvertimeWork()));
      xml.setPeakUnits(DatatypeConverter.printUnits(mpx.getPeakUnits()));
      xml.setPercentWorkComplete(NumberHelper.getBigInteger(mpx.getPercentWorkComplete()));
      xml.setPhonetics(mpx.getPhonetics());
      xml.setRegularWork(DatatypeConverter.printDuration(this, mpx.getRegularWork()));
      xml.setRemainingCost(DatatypeConverter.printCurrency(mpx.getRemainingCost()));
      xml.setRemainingOvertimeCost(DatatypeConverter.printCurrency(mpx.getRemainingOvertimeCost()));
      xml.setRemainingOvertimeWork(DatatypeConverter.printDuration(this, mpx.getRemainingOvertimeWork()));
      xml.setRemainingWork(DatatypeConverter.printDuration(this, mpx.getRemainingWork()));
      xml.setStandardRate(DatatypeConverter.printRate(mpx.getStandardRate()));
      xml.setStandardRateFormat(DatatypeConverter.printTimeUnit(mpx.getStandardRateUnits()));
      xml.setStart(mpx.getStart());
      xml.setSV(DatatypeConverter.printCurrency(mpx.getSV()));
      xml.setUID(mpx.getUniqueID());
      xml.setWork(DatatypeConverter.printDuration(this, mpx.getWork()));
      xml.setWorkGroup(mpx.getWorkGroup());
      xml.setWorkVariance(DatatypeConverter.printDurationInDecimalThousandthsOfMinutes(mpx.getWorkVariance()));

      if (mpx.getType() == ResourceType.COST)
      {
         xml.setType(ResourceType.MATERIAL);
         xml.setIsCostResource(Boolean.TRUE);
      }
      else
      {
         xml.setType(mpx.getType());
      }

      writeResourceExtendedAttributes(xml, mpx);

      writeResourceBaselines(xml, mpx);

      writeCostRateTables(xml, mpx);

      writeAvailability(xml, mpx);

      return (xml);
   }
432730
def get_chunked_content(self, chunksize=4096):
        ''''''

        # get the datastream dissemination, but return the actual http response
        r = self.obj.api.getDatastreamDissemination(self.obj.pid, self.id,
            stream=True,  asOfDateTime=self.as_of_date)
        # read and yield the response in chunks
        for chunk in r.iter_content(chunksize):
            yield chunk
426720
def _chunk(self, response, size=4096):
        
        method = response.headers.get("content-encoding")
        if method == "gzip":
            d = zlib.decompressobj(16+zlib.MAX_WBITS)
            b = response.read(size)
            while b:
                data = d.decompress(b)
                yield data
                b = response.read(size)
                del data
        else:
            while True:
                chunk = response.read(size)
                if not chunk: break
                yield chunk
378878
private BatchResult createBatchResult(RESTResponse response, DBObjectBatch dbObjBatch) {
        // See what kind of message payload, if any, we received.
        BatchResult result = null;
        if (response.getCode().isError()) {
            String errMsg = response.getBody();
            if (errMsg.length() == 0) {
                errMsg = "Unknown error; response code=" + response.getCode();
            }
            result = BatchResult.newErrorResult(errMsg);
        } else {
            result = new BatchResult(getUNodeResult(response));
            copyObjectIDsToBatch(result, dbObjBatch);
        }
        return result;
    }
1210226
protected ByteSource stream(final String resourceId) {
        return new ByteSource() {
            @Override
            public InputStream openStream() throws IOException {
                return loader.getResource(resourceId).getInputStream();
            }
        };
    }
514932
@Override
  public byte[] toBytes(JobKey jobKey) {
    if (jobKey == null) {
      return Constants.EMPTY_BYTES;
    } else {
      return ByteUtil.join(Constants.SEP_BYTES,
          Bytes.toBytes(jobKey.getCluster()),
          Bytes.toBytes(jobKey.getUserName()),
          Bytes.toBytes(jobKey.getAppId()),
          Bytes.toBytes(jobKey.getEncodedRunId()),
          idConv.toBytes(jobKey.getJobId()));
    }
  }
865041
public static <R extends Resource<?>, U extends PaginatedResponse<R>> Flux<R> getResources(U response) {
        return Flux.fromIterable(response.getResources());
    }
367626
def _BuildStreamingResponse(self, binary_stream, method_name=None):
    """"""
    precondition.AssertType(method_name, Text)

    # We get a first chunk of the output stream. This way the likelihood
    # of catching an exception that may happen during response generation
    # is much higher.
    content = binary_stream.GenerateContent()
    try:
      peek = content.next()
      stream = itertools.chain([peek], content)
    except StopIteration:
      stream = []

    response = werkzeug_wrappers.Response(
        response=stream,
        content_type="binary/octet-stream",
        direct_passthrough=True)
    response.headers["Content-Disposition"] = ((
        "attachment; filename=%s" % binary_stream.filename).encode("utf-8"))
    if method_name:
      response.headers["X-API-Method"] = method_name.encode("utf-8")

    if binary_stream.content_length:
      response.content_length = binary_stream.content_length

    return response
386490
public BatchHandler getSourceBatchHandler() {
        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.entry(tc, "getSourceBatchHandler");

        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.exit(tc, "getSourceBatchHandler", _sourceBatchHandler);

        return _sourceBatchHandler;
    }
1048410
public final byte[] getContentBytes(HttpURLConnection connection, ByteArrayPool
            byteArrayPool)
            throws IOException {
        InputStream inputStream;
        try {
            inputStream = connection.getInputStream();
        } catch (IOException ioe) {
            inputStream = connection.getErrorStream();
            if(inputStream==null) {
                throw ioe;
            }
        }
        return getContentBytes(inputStream, byteArrayPool, connection.getContentLength());
    }
418666
public JSONObject batch(List<JSONObject> actions) throws AlgoliaException {
    return postBatch(actions, RequestOptions.empty);
  }
308957
def download_yield_bytes(url, chunk_size=1024 * 1024 * 10):
    
    response = requests.get(url, stream=True)
    # raise error if download was unsuccessful
    response.raise_for_status()

    total_length = response.headers.get('content-length')
    if total_length is not None:
        total_length = float(total_length)
        length_str = "{0:.2f}Mb ".format(total_length / (1024 * 1024))
    else:
        length_str = ""

    print("Yielding {0:s} {1:s}".format(url, length_str))
    for chunk in response.iter_content(chunk_size=chunk_size):
        yield chunk
    response.close()