Example usage for java.io InputStream hashCode

List of usage examples for java.io InputStream hashCode

Introduction

In this page you can find the example usage for java.io InputStream hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:com.vmware.admiral.host.BaseManagementHostClusterIT.java

protected static File getResourceAsFile(String resourcePath) {
    try {//from  w w w  .  j a  va2s  .c  o m
        InputStream in = BaseTestCase.class.getResourceAsStream(resourcePath);
        if (in == null) {
            return null;
        }

        File tempFile = File.createTempFile(String.valueOf(in.hashCode()), ".tmp");
        tempFile.deleteOnExit();

        try (FileOutputStream out = new FileOutputStream(tempFile)) {
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
        }
        return tempFile;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:FeatureExtraction.FeatureExtractorOOXMLStructuralPathsInputStream.java

private void ExtractStructuralFeaturesInMemory(InputStream fileInputStream,
        Map<String, Integer> structuralPaths) {
    String path;/* w ww.  j av a2 s . com*/
    String directoryPath;
    String fileExtension;
    try {
        File file = new File(fileInputStream.hashCode() + "");
        try (FileOutputStream fos = new FileOutputStream(file)) {
            IOUtils.copy(fileInputStream, fos);
        }

        ZipFile zipFile = new ZipFile(file);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(String.format("Error extracting OOXML structural features from file in memory"),
                ex);
    }
}

From source file:info.rmapproject.api.responsemgr.DiscoResponseManager.java

/**
 * Creates new RMap:DiSCO from valid client-provided RDF.
 *
 * @param discoRdf the disco rdf//from   w w  w  . ja v  a  2 s.co m
 * @param contentType the content type
 * @return HTTP Response
 * @throws RMapApiException the RMap API exception
 */
public Response createRMapDiSCO(InputStream discoRdf, RDFType contentType) throws RMapApiException {
    boolean reqSuccessful = false;
    Response response = null;
    try {

        log.info("New DiSCO create request initiated (id=" + discoRdf.hashCode() + ")");

        if (discoRdf == null || discoRdf.toString().length() == 0) {
            throw new RMapApiException(ErrorCode.ER_NO_DISCO_RDF_PROVIDED);
        }
        if (contentType == null) {
            throw new RMapApiException(ErrorCode.ER_NO_CONTENT_TYPE_PROVIDED);
        }

        RMapDiSCO rmapDisco = rdfHandler.rdf2RMapDiSCO(discoRdf, contentType, Constants.BASE_URL);
        if (rmapDisco == null) {
            throw new RMapApiException(ErrorCode.ER_CORE_RDF_TO_DISCO_FAILED);
        }

        //Get the current user to associate with the DiSCO creation
        RMapRequestAgent reqAgent = apiUserService.getCurrentRequestAgent();

        RMapEventCreation discoEvent = (RMapEventCreation) rmapService.createDiSCO(rmapDisco, reqAgent);
        if (discoEvent == null) {
            throw new RMapApiException(ErrorCode.ER_CORE_CREATEDISCO_NOT_COMPLETED);
        }

        URI uDiscoURI = rmapDisco.getId().getIri();
        if (uDiscoURI == null) {
            throw new RMapApiException(ErrorCode.ER_CORE_GET_DISCOID_RETURNED_NULL);
        }
        String sDiscoURI = uDiscoURI.toString();
        if (sDiscoURI.length() == 0) {
            throw new RMapApiException(ErrorCode.ER_CORE_DISCOURI_STRING_EMPTY);
        }

        log.info("New DiSCO created (id=" + discoRdf.hashCode() + ") with URI " + sDiscoURI);

        URI uEventURI = discoEvent.getId().getIri();
        if (uEventURI == null) {
            throw new RMapApiException(ErrorCode.ER_CORE_GET_EVENTID_RETURNED_NULL);
        }
        String sEventURI = uEventURI.toString();
        if (sEventURI.length() == 0) {
            throw new RMapApiException(ErrorCode.ER_CORE_EVENTURI_STRING_EMPTY);
        }

        String newEventURL = Utils.makeEventUrl(sEventURI);
        String newDiscoUrl = Utils.makeDiscoUrl(sDiscoURI);

        String linkRel = "<" + newEventURL + ">" + ";rel=\"" + PROV.WASGENERATEDBY + "\"";

        response = Response.status(Response.Status.CREATED).entity(sDiscoURI).location(new URI(newDiscoUrl)) //switch this to location()
                .header("Link", linkRel) //switch this to link()
                .build();

        reqSuccessful = true;
    } catch (RMapApiException ex) {
        throw RMapApiException.wrap(ex);
    } catch (RMapDefectiveArgumentException ex) {
        throw RMapApiException.wrap(ex, ErrorCode.ER_GET_DISCO_BAD_ARGUMENT);
    } catch (RMapException ex) {
        throw RMapApiException.wrap(ex, ErrorCode.ER_CORE_GENERIC_RMAP_EXCEPTION);
    } catch (Exception ex) {
        throw RMapApiException.wrap(ex, ErrorCode.ER_UNKNOWN_SYSTEM_ERROR);
    } finally {
        if (rmapService != null)
            rmapService.closeConnection();
        if (!reqSuccessful && response != null)
            response.close();
    }
    return response;
}

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

protected void setInputStream(final InputStream servletIs) {
    this.servletIs = new ServletInputStream() {

        public int available() throws IOException {
            return servletIs.available();
        }//w  ww  . jav  a  2 s . co  m

        public void close() throws IOException {
            servletIs.close();
        }

        public boolean equals(Object obj) {
            return servletIs.equals(obj);
        }

        public int hashCode() {
            return servletIs.hashCode();
        }

        public void mark(int readlimit) {
            servletIs.mark(readlimit);
        }

        public boolean markSupported() {
            return servletIs.markSupported();
        }

        public int read(byte[] b, int off, int len) throws IOException {
            return servletIs.read(b, off, len);
        }

        public int read(byte[] b) throws IOException {
            return servletIs.read(b);
        }

        public void reset() throws IOException {
            servletIs.reset();
        }

        public long skip(long n) throws IOException {
            return servletIs.skip(n);
        }

        public String toString() {
            return servletIs.toString();
        }

        @Override
        public int read() throws IOException {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.apache.synapse.commons.json.JsonUtil.java

/**
 * Returns a reusable cached copy of the JSON stream contained in the provided Message Context.
 *
 * @param messageContext Axis2 Message context that contains a JSON payload.
 * @return {@link java.io.InputStream}//  w w  w  .ja  v  a2s .  com
 */
private static InputStream cachedCopyOfJsonPayload(MessageContext messageContext) {
    if (messageContext == null) {
        logger.error("#cachedCopyOfJsonPayload. Cannot copy JSON stream from message context. [null].");
        return null;
    }
    InputStream jsonStream = jsonStream(messageContext, true);
    if (jsonStream == null) {
        logger.error("#cachedCopyOfJsonPayload. Cannot copy JSON stream from message context. [null] stream.");
        return null;
    }
    String inputStreamCache = Long.toString(jsonStream.hashCode());
    Object o = messageContext.getProperty(inputStreamCache);
    if (o instanceof InputStream) {
        InputStream inputStream = (InputStream) o;
        try {
            inputStream.reset();
            if (logger.isDebugEnabled()) {
                logger.debug("#cachedCopyOfJsonPayload. Cache HIT");
            }
            return inputStream;
        } catch (IOException e) {
            logger.warn("#cachedCopyOfJsonPayload. Could not reuse the cached input stream. Error>>> "
                    + e.getLocalizedMessage());
        }
    }
    org.apache.commons.io.output.ByteArrayOutputStream out = new org.apache.commons.io.output.ByteArrayOutputStream();
    try {
        IOUtils.copy(jsonStream, out);
        out.flush();
        InputStream inputStream = toReadOnlyStream(new ByteArrayInputStream(out.toByteArray()));
        messageContext.setProperty(inputStreamCache, inputStream);
        if (logger.isDebugEnabled()) {
            logger.debug("#cachedCopyOfJsonPayload. Cache MISS");
        }
        return inputStream;
    } catch (IOException e) {
        logger.error("#cachedCopyOfJsonPayload. Could not copy the JSON stream from message context. Error>>> "
                + e.getLocalizedMessage());
    }
    return null;
}

From source file:org.wso2.carbon.business.rules.templates.editor.core.internal.TemplatesEditorMicroservice.java

private File getResourceAsFile(String resourcePath) {
    try {/* w w w .  j  a v a2s .c  o m*/
        InputStream in = this.getClass().getResource(resourcePath).openStream();
        if (in == null) {
            return null;
        }
        File tempFile = File.createTempFile(String.valueOf(in.hashCode()), ".tmp");
        tempFile.deleteOnExit();
        FileOutputStream out = new FileOutputStream(tempFile);
        IOUtils.copy(in, out);
        return tempFile;
    } catch (Throwable e) {
        log.warn("Couldn't load requested resource: " + resourcePath);
        return null;
    }
}

From source file:org.wso2.carbon.siddhi.editor.core.internal.ServiceComponent.java

private File getResourceAsFile(String resourcePath) {
    try {// www .j a v a2  s .com
        InputStream in = this.getClass().getResource(resourcePath).openStream();
        if (in == null) {
            return null;
        }
        File tempFile = File.createTempFile(String.valueOf(in.hashCode()), ".tmp");
        tempFile.deleteOnExit();
        FileOutputStream out = new FileOutputStream(tempFile);
        IOUtils.copy(in, out);
        return tempFile;
    } catch (Exception e) {
        log.warn("Couldn't load requested resource: " + resourcePath);
        return null;
    }
}