上传文件和元数据

@param client
@param inputStream
@param fileSize
@param fileExtName
@param metaDataSet
@return
960054
private StorePath uploadFileAndMetaData(StorageNode client, InputStream inputStream, long fileSize,
                                            String fileExtName, Set<MetaData> metaDataSet) {
        // 上传文件
        StorageUploadFileCommand command = new StorageUploadFileCommand(client.getStoreIndex(), inputStream,
                fileExtName, fileSize, false);
        StorePath path = connectionManager.executeFdfsCmd(client.getInetSocketAddress(), command);
        // 上传metadata
        if (hasMetaData(metaDataSet)) {
            StorageSetMetadataCommand setMDCommand = new StorageSetMetadataCommand(path.getGroup(), path.getPath(),
                    metaDataSet, StorageMetadataSetType.STORAGE_SET_METADATA_FLAG_OVERWRITE);
            connectionManager.executeFdfsCmd(client.getInetSocketAddress(), setMDCommand);
        }
        return path;
    }
322086
private ClientProperties onParseXML(String propertyFileName, PersistenceUnitMetadata puMetadata)
    {
        InputStream inStream = puMetadata.getClassLoader().getResourceAsStream(propertyFileName);
        if (inStream == null)
        {
            propertyFileName = KunderaCoreUtils.resolvePath(propertyFileName);
            try
            {
                inStream = new FileInputStream(new File(propertyFileName));
            }
            catch (FileNotFoundException e)
            {
                log.warn("File {} not found, Caused by ", propertyFileName);
                return null;
            }

        }

        if (inStream != null)
        {
            xStream = getXStreamObject();
            Object o = xStream.fromXML(inStream);
            return (ClientProperties) o;
        }

        return null;
    }
923529
public String uploadImage(byte[] image, byte[] watermark, String ext, Map<String, String> metaInfo) {
        return uploadImage(image, watermark, ext, metaInfo, DEFAULT_OPACITY, DEFAULT_LOCATION, DEFAULT_MARGIN);
    }
139720
@SuppressWarnings("unchecked")
    public <T extends IEntity> T upload(T entity, InputStream docContent) throws FMSException {

        IntuitMessage intuitMessage = prepareUpload(entity, docContent);

        //execute interceptors
        executeInterceptors(intuitMessage);

        return (T) getReturnEntity(intuitMessage);
    }
782174
static public MetaDataInputStream getMetaDataInputStream(
      FSDatasetInterface dataset, int namespace, Block b) throws IOException {
    File checksumFile = getMetaFile(dataset, namespace, b);
    return new MetaDataInputStream(new FileInputStream(checksumFile),
                                                    checksumFile.length());
  }
528315
public HttpEntity<byte[]> getMetadata(HttpServletRequest request, @RequestHeader(name = "Accept", required = false) String acceptHeader) {

    logger.debug("Request to download metadata from {}", request.getRemoteAddr());

    try {

      // Check if the metadata is up-to-date according to how the container was configured.
      //
      if (this.metadataContainer.updateRequired(true)) {
        logger.debug("Metadata needs to be updated ...");
        this.metadataContainer.update(true);
        logger.debug("Metadata was updated and signed");
      }
      else {
        logger.debug("Metadata is up-to-date, using cached metadata");
      }

      // Get the DOM for the metadata and serialize it.
      //
      Element dom = this.metadataContainer.marshall();

      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      SerializeSupport.writeNode(dom, stream);

      // Assign the HTTP headers.
      //
      HttpHeaders header = new HttpHeaders();
      if (acceptHeader != null && !acceptHeader.contains(APPLICATION_SAML_METADATA)) {
        header.setContentType(MediaType.APPLICATION_XML);
      }
      else {
        header.setContentType(MediaType.valueOf(APPLICATION_SAML_METADATA));
      }
      // TODO: turn off caching

      byte[] documentBody = stream.toByteArray();
      header.setContentLength(documentBody.length);
      return new HttpEntity<byte[]>(documentBody, header);
    }
    catch (SignatureException | MarshallingException e) {
      logger.error("Failed to return valid metadata", e);
      return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
1162495
public void setFile(InputStream inputStream, String filename, long fileSize) {
        this.setFile(inputStream, filename);
        this.fileSize = fileSize;
    }
1191908
private void openInputFile(final String inputFileName) throws IOException
	{
		myInputFile = new File(inputFileName);
		myInputStream = new FileInputStream(myInputFile);
		myStreamReader = new InputStreamReader(myInputStream, getInputEncodingCode());
		myBufferedReader = new BufferedReader(myStreamReader);
		myLineReader = new LineNumberReader(myBufferedReader);
	}
614112
@Override
	public void loadInputData(String fileName) {
		Reader r = media.openFile(fileName);

		List<PathLabel> refs = new ArrayList<>();
		try {
			BufferedReader reader = new BufferedReader(r);

			String line;
			while( (line = reader.readLine()) != null ) {

				String[]z = line.split(":");
				String[] names = new String[z.length-1];
				for( int i = 1; i < z.length; i++ ) {
					names[i-1] = baseDirectory+z[i];
				}

				refs.add(new PathLabel(z[0],names));
			}

			setInputList(refs);

		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
1151831
@GetMapping(path = WSFederationConstants.ENDPOINT_FEDERATION_METADATA)
    public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
        try {
            response.setContentType(MediaType.TEXT_HTML_VALUE);
            val out = response.getWriter();
            val metadata = WSFederationMetadataWriter.produceMetadataDocument(casProperties);
            out.write(DOM2Writer.nodeToString(metadata));
        } catch (final Exception ex) {
            LOGGER.error("Failed to get metadata document", ex);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
823755
public boolean upload(String path, String fileName, InputStream fileStream) {
		try {
			client.setFileType(FTPClient.BINARY_FILE_TYPE);
		} catch (IOException e) {
			throw new FtpException(e);
		}
		
		if(StrUtil.isNotBlank(path)) {
			mkDirs(path);
			boolean isOk = cd(path);
			if(false == isOk) {
				return false;
			}
		}
		
		try {
			return client.storeFile(fileName, fileStream);
		} catch (IOException e) {
			throw new FtpException(e);
		}
	}
533745
private void copyStream(InputStream inputStream) throws IOException {
		OutputStream outputStream = null;
		try {
			outputStream = getContext().getOutputStream();
			byte[] buffer = new byte[65535];
			int bufferLen;
			int totalLen = 0;
			while ((bufferLen = inputStream.read(buffer)) > 0) {
				outputStream.write(buffer, 0, bufferLen);
				totalLen += bufferLen;
			}
			getContext().getResponse().setContentLength(totalLen);
		} finally {
			if (outputStream != null) {
				outputStream.flush();
			}
		}
	}
1029725
function buildMetadata(f, metadataTarget, options, isText) {

  var ext = path.extname(f);
  var name = path.basename(f, ext);

  var data = buildMetadataContent(name, options, ext, isText);

  fs.ensureFileSync(metadataTarget);
  fs.writeFileSync(metadataTarget, data, 'utf8');

}
716280
public void setInputStream(InputStream inputStream, long inputStreamLength) {
		// close last file when set a new inputStream
		if (this.isUploadFile){
			try{
				this.inputStream.close();
			}
			catch (Exception e){
			}
		}

		if (inputStream instanceof FDSProgressInputStream){
			this.inputStream = (FDSProgressInputStream) inputStream;
		}
		else {
			this.inputStream = new FDSProgressInputStream(inputStream, this.progressListener);
		}
		if (this.progressListener != null){
			this.progressListener.setTransferred(0);
			this.progressListener.setTotal(inputStreamLength);
		}
		this.isUploadFile = false;
		this.inputStreamLength = inputStreamLength;
	}
1372325
public static Document getDocument(InputStream inputStream) {
        Document result = null;

        try {
            // memory optimization over minor performance sacrifice
            synchronized (XmlRepositoryFactory.class) {
                if (documentBuilder == null) {
                    documentBuilder = builderFactory.newDocumentBuilder();
                }

                result = documentBuilder.parse(inputStream);
            }
        } catch (ParserConfigurationException ex) {
            throw new MjdbcRuntimeException(ex);
        } catch (SAXException ex) {
            throw new MjdbcRuntimeException(ex);
        } catch (IOException ex) {
            throw new MjdbcRuntimeException(ex);
        }

        return result;
    }
213912
private void uploadThumbImage(StorageNode client, InputStream inputStream, String masterFilename,
                                  String fileExtName) {
        ByteArrayInputStream thumbImageStream = null;
        try {
            thumbImageStream = generateThumbImageByDefault(inputStream);// getFileInputStream
            // 获取文件大小
            long fileSize = thumbImageStream.available();
            // 获取缩略图前缀
            String prefixName = thumbImageConfig.getPrefixName();
            LOGGER.debug("上传缩略图主文件={},前缀={}", masterFilename, prefixName);
            StorageUploadSlaveFileCommand command = new StorageUploadSlaveFileCommand(thumbImageStream, fileSize,
                    masterFilename, prefixName, fileExtName);
            connectionManager.executeFdfsCmd(client.getInetSocketAddress(), command);

        } catch (IOException e) {
            LOGGER.error("upload ThumbImage error", e);
            throw new FdfsUploadImageException("upload ThumbImage error", e.getCause());
        } finally {
            IOUtils.closeQuietly(thumbImageStream);
        }
    }
247574
public void setMetadata(String moduleKeyWithBranch, final DefaultInputFile inputFile, Charset defaultEncoding) {
    CharsetDetector charsetDetector = new CharsetDetector(inputFile.path(), defaultEncoding);
    try {
      Charset charset;
      if (charsetDetector.run()) {
        charset = charsetDetector.charset();
      } else {
        LOG.debug("Failed to detect a valid charset for file '{}'. Using default charset.", inputFile);
        charset = defaultEncoding;
      }
      InputStream is = charsetDetector.inputStream();
      inputFile.setCharset(charset);
      Metadata metadata = fileMetadata.readMetadata(is, charset, inputFile.absolutePath(), exclusionsScanner.createCharHandlerFor(inputFile));
      inputFile.setMetadata(metadata);
      inputFile.setStatus(statusDetection.status(moduleKeyWithBranch, inputFile, metadata.hash()));
      LOG.debug("'{}' generated metadata{} with charset '{}'", inputFile, inputFile.type() == Type.TEST ? " as test " : "", charset);
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }