Package org.sonatype.nexus.proxy.item

Examples of org.sonatype.nexus.proxy.item.ContentLocator


  @Override
  public void store(String content, String path)
      throws IOException
  {
    ContentLocator contentLocator = new StringContentLocator(content);

    putStorageItem(path, contentLocator);
  }
View Full Code Here


    if (attributes != null) {
      item.getRepositoryItemAttributes().overlayAttributes(attributes);
    }
    else {
      // we are fixing md if we can
      ContentLocator is = null;
      if (item instanceof StorageFileItem &&
          ((StorageFileItem) item).getContentLocator().isReusable()) {
        is = ((StorageFileItem) item).getContentLocator();
      }
View Full Code Here

  public void storeItem(Repository repository, StorageItem item)
      throws UnsupportedStorageOperationException, LocalStorageException
  {
    final File target;
    final ContentLocator originalContentLocator;
    if (item instanceof StorageFileItem) {
      originalContentLocator = ((StorageFileItem) item).getContentLocator();
    }
    else {
      originalContentLocator = null;
    }
    try {
      // set some sanity stuff
      item.setStoredLocally(System.currentTimeMillis());
      item.setRemoteChecked(item.getStoredLocally());
      item.setExpired(false);

      ContentLocator cl = null;

      if (item instanceof StorageFileItem) {
        StorageFileItem fItem = (StorageFileItem) item;

        prepareStorageFileItemForStore(fItem);

        cl = fItem.getContentLocator();
      }
      else if (item instanceof StorageLinkItem) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
          getLinkPersister().writeLinkContent((StorageLinkItem) item, bos);
        }
        catch (IOException e) {
          // should not happen, look at implementation
          // we will handle here two byte array backed streams!
          throw new LocalStorageException("Problem ", e);
        }

        cl = new ByteArrayContentLocator(bos.toByteArray(), "text/xml");
      }

      target = getFileFromBase(repository, item.getResourceStoreRequest());

      getFSPeer().storeItem(repository, getBaseDir(repository, item.getResourceStoreRequest()), item, target, cl);
    }
    finally {
      // NEXUS-5468: Ensure that in case of file item with prepared content
      // (typically those coming from RRS, as the content is actually wrapped HTTP response body, hence not reusable)
      // get closed irrelevant of the actual outcome. If all went right, stream was already closed,
      // and we will be "punished" by one extra (redundant) call to Closeable#close().
      if (originalContentLocator instanceof Closeable) {
        IOUtils.closeQuietly((Closeable) originalContentLocator);
      }
    }

    if (item instanceof StorageFileItem) {
      // replace content locator transparently, if we just consumed a non-reusable one
      // Hint: in general, those items coming from user uploads or remote proxy caching requests are non
      // reusable ones
      ((StorageFileItem) item).setContentLocator(new FileContentLocator(target,
          ((StorageFileItem) item).getMimeType()));
    }

    final ContentLocator mdis =
        item instanceof StorageFileItem ? ((StorageFileItem) item).getContentLocator() : null;

    try {
      repository.getAttributesHandler().storeAttributes(item, mdis);
    }
View Full Code Here

    String mimeType = getMimeSupport().guessMimeTypeFromPath(getMimeRulesSource(), digestFileName);

    byte[] bytes = (digest + '\n').getBytes("UTF-8");

    ContentLocator contentLocator = new ByteArrayContentLocator(bytes, mimeType);

    ResourceStoreRequest req = new ResourceStoreRequest(digestFileName);

    req.getRequestContext().setParentContext(request.getRequestContext());
View Full Code Here

  {
    // we are creating file maven-metadata.xml, and ask the MimeUtil for it's exact MIME type to honor potential
    // user configuration
    String mimeType = getMimeSupport().guessMimeTypeFromPath(getMimeRulesSource(), "maven-metadata.xml");

    ContentLocator contentLocator = new ByteArrayContentLocator(content, mimeType);

    DefaultStorageCompositeFileItem result =
        new DefaultStorageCompositeFileItem(this, request, true, false, contentLocator, sources);

    result.setCreated(getNewestCreatedDate(sources));
View Full Code Here

            content = mdOutput.toByteArray();
          }

          String mimeType =
              getMimeSupport().guessMimeTypeFromPath(getMimeRulesSource(), request.getRequestPath());
          ContentLocator contentLocator = new ByteArrayContentLocator(content, mimeType);

          DefaultStorageFileItem result =
              new DefaultStorageFileItem(this, request, true, false, contentLocator);
          result.setCreated(mdItem.getCreated());
          result.setModified(System.currentTimeMillis());
View Full Code Here

        if (mirrorsURL != null) {
          // The remote repository is a SimpleArtifactRepository with mirrors configured
          log.debug(
              "Repository " + getId() + ": configureMirrors: found single mirrors URL=" + mirrorsURL);
          final StorageFileItem remoteMirrorsItem = getMirrorsItemRemote(mirrorsURL);
          final ContentLocator content =
              new PreparedContentLocator(((StorageFileItem) remoteMirrorsItem).getInputStream(),
                  "text/xml", remoteMirrorsItem.getLength());
          mirrorsItem =
              new DefaultStorageFileItem(this, new ResourceStoreRequest(PRIVATE_MIRRORS_PATH),
                  true /* isReadable */, false /* isWritable */, content);
View Full Code Here

  }

  private void storeItemFromFile(final String path, final File file, final P2ProxyRepository repository)
      throws LocalStorageException, UnsupportedStorageOperationException
  {
    final ContentLocator content = new FileContentLocator(file, "text/xml");
    final DefaultStorageFileItem storageItem =
        new DefaultStorageFileItem(repository, new ResourceStoreRequest(path), true /* isReadable */,
            false /* isWritable */, content);
    repository.getLocalStorage().storeItem(repository, storageItem);
  }
View Full Code Here

  @Test
  public void testBundleItem1()
      throws Exception
  {
    final ContentLocator content = new AbstractContentLocator("application/java-archive", false, ContentLocator.UNKNOWN_LENGTH)
    {
      public InputStream getContent()
          throws IOException
      {
        return getResourceAsStream("/obr/jars/osgi.core.jar");
View Full Code Here

  @Test
  public void testBundleItem2()
      throws Exception
  {
    final ContentLocator content = new AbstractContentLocator("application/java-archive", false, ContentLocator.UNKNOWN_LENGTH)
    {
      public InputStream getContent()
          throws IOException
      {
        return getResourceAsStream("/obr/jars/org.eclipse.core.runtime_3.4.0.v20080512.jar");
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.item.ContentLocator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.