Example usage for java.net URI toASCIIString

List of usage examples for java.net URI toASCIIString

Introduction

In this page you can find the example usage for java.net URI toASCIIString.

Prototype

public String toASCIIString() 

Source Link

Document

Returns the content of this URI as a US-ASCII string.

Usage

From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java

@Override
public ODataEntitySet getODataEntitySet(final FeedResource resource, final URI defaultBaseURI) {
    if (LOG.isDebugEnabled()) {
        final StringWriter writer = new StringWriter();
        client.getSerializer().feed(resource, writer);
        writer.flush();/*w ww  . j a  v a2  s  . c o m*/
        LOG.debug("FeedResource -> ODataEntitySet:\n{}", writer.toString());
    }

    final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;

    final URI next = resource.getNext();

    final ODataEntitySet entitySet = next == null ? ODataObjectFactory.newEntitySet()
            : ODataObjectFactory.newEntitySet(URIUtils.getURI(base, next.toASCIIString()));

    if (resource.getCount() != null) {
        entitySet.setCount(resource.getCount());
    }

    for (EntryResource entryResource : resource.getEntries()) {
        entitySet.addEntity(getODataEntity(entryResource));
    }

    return entitySet;
}

From source file:org.apache.olingo.ext.proxy.commons.StructuredComposableInvokerInvocationHandler.java

public StructuredComposableInvokerInvocationHandler(final URI uri, final Map<String, ClientValue> parameters,
        final Operation operation, final EdmOperation edmOperation, final Type[] references,
        final EdmTypeInfo returnType, final AbstractService<?> service) {

    super(uri, parameters, operation, edmOperation, references, service);

    if (!edmOperation.getReturnType().isCollection()) {
        if (returnType.isEntityType()) {
            this.structuredHandler = EntityInvocationHandler.getInstance(uri, targetRef, service);
        }/*from   ww w . ja v a  2  s.  c  o m*/
        if (returnType.isComplexType()) {
            this.structuredHandler = ComplexInvocationHandler.getInstance(targetRef, service,
                    service.getClient().newURIBuilder(uri.toASCIIString()));
        }
    }
}

From source file:com.msopentech.odatajclient.engine.data.impl.AbstractODataBinder.java

@Override
public ODataEntitySet getODataEntitySet(final Feed resource, final URI defaultBaseURI) {
    if (LOG.isDebugEnabled()) {
        final StringWriter writer = new StringWriter();
        client.getSerializer().feed(resource, writer);
        writer.flush();//from w w  w.  jav a 2  s .  c  o m
        LOG.debug("FeedResource -> ODataEntitySet:\n{}", writer.toString());
    }

    final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;

    final URI next = resource.getNext();

    final ODataEntitySet entitySet = next == null ? client.getObjectFactory().newEntitySet()
            : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));

    if (resource.getCount() != null) {
        entitySet.setCount(resource.getCount());
    }

    for (Entry entryResource : resource.getEntries()) {
        entitySet.addEntity(getODataEntity(entryResource));
    }

    return entitySet;
}

From source file:com.brightcove.player.samples.offlineplayback.VideoListAdapter.java

/**
 * Updates the row at the given position to reflect the changes in the underlying data.
 *
 * @param holder   reference to the view holder.
 * @param position the position of the row that should be updated.
 * @param status   optional current download status.
 */// w w  w. j av  a2 s .  c o  m
public void updateView(@NonNull final ViewHolder holder, int position, @Nullable DownloadStatus status) {
    holder.video = videoList.get(position);
    final Video video = holder.getVideo();

    if (video.isOfflinePlaybackAllowed()) {
        final Date expiryDate = video.getLicenseExpiryDate();
        if (expiryDate == null) {
            holder.videoLicenseText.setText("Buy or rent for offline playback");
            holder.videoStatusText.setVisibility(View.GONE);
            holder.rentButton.setVisibility(View.VISIBLE);
            holder.buyButton.setVisibility(View.VISIBLE);
            holder.deleteButton.setVisibility(View.GONE);
            holder.downloadButton.setVisibility(View.GONE);
            holder.downloadProgressBar.setVisibility(View.GONE);
            holder.pauseButton.setVisibility(View.GONE);
            holder.resumeButton.setVisibility(View.GONE);
        } else {
            holder.rentButton.setVisibility(View.GONE);
            holder.buyButton.setVisibility(View.GONE);
            holder.pauseButton.setVisibility(View.GONE);
            holder.resumeButton.setVisibility(View.GONE);

            if (video.isOwned()) {
                holder.videoLicenseText.setText("Owned");
            } else {
                holder.videoLicenseText.setText(String.format("Rental Expires: %s %s",
                        DateFormat.getMediumDateFormat(holder.context).format(expiryDate),
                        DateFormat.getTimeFormat(holder.context).format(expiryDate)));
            }

            if (status == null) {
                holder.videoStatusText.setText("Checking download status...");
                holder.videoStatusText.setVisibility(View.VISIBLE);
                holder.deleteButton.setVisibility(View.GONE);
                holder.downloadButton.setVisibility(View.GONE);
                holder.downloadProgressBar.setVisibility(View.GONE);

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        final DownloadStatus status = catalog.getVideoDownloadStatus(holder.video);
                        holder.itemView.post(new Runnable() {
                            @Override
                            public void run() {
                                updateDownloadStatus(holder, status);
                            }
                        });
                    }
                }).start();

            } else {
                updateDownloadStatus(holder, status);
            }
        }
    } else {
        holder.videoLicenseText.setVisibility(View.GONE);
        holder.videoStatusText.setText("Online Only");
        holder.videoStatusText.setVisibility(View.VISIBLE);
        holder.rentButton.setVisibility(View.GONE);
        holder.buyButton.setVisibility(View.GONE);
        holder.downloadButton.setVisibility(View.GONE);
        holder.deleteButton.setVisibility(View.GONE);
        holder.downloadProgressBar.setVisibility(View.GONE);
        holder.pauseButton.setVisibility(View.GONE);
        holder.resumeButton.setVisibility(View.GONE);
    }

    holder.videoTitleText.setText(video.getName());

    URI imageUri = video.getStillImageUri();
    if (imageUri == null) {
        holder.videoThumbnailImage.setImageResource(R.drawable.movie);
    } else {
        Picasso.with(holder.context).load(imageUri.toASCIIString()).into(holder.videoThumbnailImage);
    }

    int duration = video.getDuration();
    if (duration > 0) {
        holder.videoDurationText.setText(millisecondsToString(duration));
        holder.videoDurationText.setVisibility(View.VISIBLE);
    } else {
        holder.videoDurationText.setText(null);
        holder.videoDurationText.setVisibility(View.GONE);
    }

}

From source file:com.marklogic.contentpump.CompressedRDFReader.java

@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
    boolean stillReading = super.nextKeyValue();
    if (stillReading) {
        return true;
    }// ww  w  .  j ava  2 s  .co  m

    // Ok, we've run out of data in the current file, are there more?
    URI zipURI = file.toUri();
    if (codec.equals(CompressionCodec.ZIP)) {
        ZipInputStream zis = (ZipInputStream) zipIn;

        ByteArrayOutputStream baos;
        while ((currZipEntry = zis.getNextEntry()) != null) {
            if (currZipEntry.getSize() == 0) {
                continue;
            }

            long size = currZipEntry.getSize();
            if (size == -1) {
                baos = new ByteArrayOutputStream();
                // if we don't know the size, assume it's big!
                initParser(zipURI.toASCIIString() + "/" + currZipEntry.getName(), INMEMORYTHRESHOLD);
            } else {
                baos = new ByteArrayOutputStream((int) size);
                initParser(zipURI.toASCIIString() + "/" + currZipEntry.getName(), size);
            }
            int nb;
            while ((nb = zis.read(buf, 0, buf.length)) != -1) {
                baos.write(buf, 0, nb);
            }

            parse(currZipEntry.getName(), new ByteArrayInputStream(baos.toByteArray()));
            boolean gotTriples = super.nextKeyValue();
            if (gotTriples) {
                return true;
            }
        }
        // end of zip
        if (iterator != null && iterator.hasNext()) {
            close();
            initStream(iterator.next());
            return super.nextKeyValue();
        }

        return false;
    } else {
        return false;
    }
}

From source file:org.apache.olingo.client.core.serialization.AbstractODataBinder.java

@Override
public CommonODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
    if (LOG.isDebugEnabled()) {
        final StringWriter writer = new StringWriter();
        try {//www.  j av  a  2 s  . co  m
            client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
        } catch (final ODataSerializerException e) {
        }
        writer.flush();
        LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
    }

    final URI base = resource.getContextURL() == null ? resource.getPayload().getBaseURI()
            : ContextURLParser.parse(resource.getContextURL()).getServiceRoot();

    final URI next = resource.getPayload().getNext();

    final CommonODataEntitySet entitySet = next == null ? client.getObjectFactory().newEntitySet()
            : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));

    if (resource.getPayload().getCount() != null) {
        entitySet.setCount(resource.getPayload().getCount());
    }

    for (Entity entityResource : resource.getPayload().getEntities()) {
        add(entitySet, getODataEntity(
                new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
    }

    return entitySet;
}

From source file:com.xmlcalabash.core.XProcRuntime.java

public Vector<XdmNode> getCollection(URI href) {
    if (collections == null) {
        return null;
    }//w ww.j a v a2  s.c  o  m
    if (collections.containsKey(href.toASCIIString())) {
        return collections.get(href.toASCIIString());
    }
    return null;
}

From source file:org.apache.olingo.client.core.serialization.AbstractODataBinder.java

@Override
public Entity getEntity(final CommonODataEntity odataEntity) {
    final Entity entity = new EntityImpl();

    entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI odataEditLink = odataEntity.getEditLink();
    if (odataEditLink != null) {
        final LinkImpl editLink = new LinkImpl();
        editLink.setTitle(entity.getType());
        editLink.setHref(odataEditLink.toASCIIString());
        editLink.setRel(Constants.EDIT_LINK_REL);
        entity.setEditLink(editLink);// ww  w  .  ja v a  2s.c o m
    }

    if (odataEntity.isReadOnly()) {
        final LinkImpl selfLink = new LinkImpl();
        selfLink.setTitle(entity.getType());
        selfLink.setHref(odataEntity.getLink().toASCIIString());
        selfLink.setRel(Constants.SELF_LINK_REL);
        entity.setSelfLink(selfLink);
    }
    // -------------------------------------------------------------

    links(odataEntity, entity);

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : odataEntity.getMediaEditLinks()) {
        LOG.debug("Append edit-media link\n{}", link);
        entity.getMediaEditLinks().add(getLink(link));
    }
    // -------------------------------------------------------------

    if (odataEntity.isMediaEntity()) {
        entity.setMediaContentSource(odataEntity.getMediaContentSource());
        entity.setMediaContentType(odataEntity.getMediaContentType());
        entity.setMediaETag(odataEntity.getMediaETag());
    }

    for (CommonODataProperty property : odataEntity.getProperties()) {
        entity.getProperties().add(getProperty(property));
    }

    return entity;
}

From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java

public void testUriDeserialization() {
    String uriValue = "http://google.com/";
    String json = '"' + uriValue + '"';
    URI target = gson.fromJson(json, URI.class);
    assertEquals(uriValue, target.toASCIIString());

    target = oson.fromJson(json, URI.class);
    assertEquals(uriValue, target.toASCIIString());
}

From source file:ddf.catalog.resourceretriever.LocalResourceRetriever.java

@Override
public ResourceResponse retrieveResource(long bytesToSkip) throws ResourceNotFoundException {
    final String methodName = "retrieveResource";
    LOGGER.trace("ENTERING: {}", methodName);
    ResourceResponse resource = null;//from   w w  w.  j  a va2  s  . c om

    if (resourceUri == null) {
        throw new ResourceNotFoundException("Unable to find resource due to null URI");
    }

    Map<String, Serializable> props = new HashMap<>(properties);

    if (bytesToSkip > 0) {
        props.put(BYTES_TO_SKIP, bytesToSkip);
    }

    URI derivedUri = null;
    Serializable serializable = props.get(ContentItem.QUALIFIER_KEYWORD);
    if (serializable != null && serializable instanceof String) {
        LOGGER.debug(
                "Received qualifier in request properties, looking for qualified content on metacard with id [{}]",
                resourceMetacard.getId());

        String fragment = (String) serializable;
        derivedUri = getDerivedUriWithFragment(resourceMetacard, fragment);
    }

    String scheme;
    URI resourceRetrievalUri;
    if (derivedUri == null) {
        scheme = resourceUri.getScheme();
        resourceRetrievalUri = resourceUri;
    } else {
        scheme = derivedUri.getScheme();
        resourceRetrievalUri = derivedUri;
    }

    for (ResourceReader reader : resourceReaders) {
        if (reader != null && reader.getSupportedSchemes().contains(scheme)) {
            try {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Found an acceptable resource reader ({}) for URI {}", reader.getId(),
                            resourceRetrievalUri.toASCIIString());
                }
                resource = reader.retrieveResource(resourceRetrievalUri, props);
                if (resource != null) {
                    break;
                } else {
                    LOGGER.debug(
                            "Resource returned from ResourceReader {} was null. Checking other readers for URI: {}",
                            reader.getId(), resourceRetrievalUri);
                }
            } catch (ResourceNotFoundException | ResourceNotSupportedException | IOException e) {
                LOGGER.debug("Product not found using resource reader with name {}", reader.getId(), e);
            }
        }
    }

    if (resource == null) {
        throw new ResourceNotFoundException(
                "Resource Readers could not find resource (or returned null resource) for URI: "
                        + resourceRetrievalUri.toASCIIString() + ". Scheme: "
                        + resourceRetrievalUri.getScheme());
    }
    LOGGER.debug("Received resource, sending back: {}", resource.getResource().getName());
    LOGGER.trace("EXITING: {}", methodName);

    return resource;
}