Get Optional {@link CopyableFileWatermarkGenerator} from {@link State}.
554104
public static Optional<CopyableFileWatermarkGenerator> getCopyableFileWatermarkGenerator(State state)
      throws IOException {
    try {
      if (state.contains(WATERMARK_CREATOR)) {
        Class<?> watermarkCreatorClass = Class.forName(state.getProp(WATERMARK_CREATOR));
        return Optional.of((CopyableFileWatermarkGenerator) watermarkCreatorClass.newInstance());
      } else {
        return Optional.absent();
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
      throw new IOException("Failed to instantiate watermarkCreator.");
    }
  }
96852
public Optional<InputStream> getFile() {
        if (!this.files.isEmpty()) {
            return Optional.of(this.files.get(0));
        }

        return Optional.empty();
    }
123927
public void copyFrom(StateSet other) {
        this.isTop = other.isTop;
        this.isBottom = other.isBottom;
        this.onExceptionPath = other.onExceptionPath;
        this.stateMap.clear();
        for (State state : other.stateMap.values()) {
            State dup = state.duplicate();
            this.stateMap.put(dup.getObligationSet(), dup);
        }
    }
6879
public TempStream copy()
  {
    TempStream newStream = new TempStream();

    TempBuffer ptr = _head;

    for (; ptr != null; ptr = ptr.next()) {
      TempBuffer newPtr = TempBuffer.create();
      
      if (newStream._tail != null)
        newStream._tail.next(newPtr);
      else
        newStream._head = newPtr;
      newStream._tail = newPtr;

      newPtr.write(ptr.buffer(), 0, ptr.length());
    }

    return newStream;
  }
138932
public long copyFileFromImpl(InputStream src) throws FileNotFoundException, CopyFileFromException {
        try (OutputStream dest = newOutputStream()) {
            return getWorld().getBuffer().copy(src, dest);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw new CopyFileFromException(this, e);
        }
    }
558863
@Nonnull
  public static NonBlockingByteArrayOutputStream getCopy (@Nonnull @WillClose final InputStream aIS)
  {
    final int nAvailable = Math.max (DEFAULT_BUFSIZE, getAvailable (aIS));
    final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (nAvailable);
    copyInputStreamToOutputStreamAndCloseOS (aIS, aBAOS);
    return aBAOS;
  }
254858
public JMFMessage copy() {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.entry(this, tc, "copy");
    JMFMessage copy;

    synchronized (getMessageLockArtefact()) {
      if (map == null) {
        // If there is no map, then this is already become just a delegator, so
        // the copy does not need to include the compatibility wrapper.
        copy = ((JMFMessage)encoding).copy();
      }
      else {
        // In the usual case, we maintain a compatibility layer
        copy = new JSCompatibleMessageImpl(this);
      }
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "copy", copy);
    return copy;
  }
236217
@PublicEvolving
	public QueryableStateStream<KEY, T> asQueryableState(String queryableStateName) {
		ValueStateDescriptor<T> valueStateDescriptor = new ValueStateDescriptor<T>(
				UUID.randomUUID().toString(),
				getType());

		return asQueryableState(queryableStateName, valueStateDescriptor);
	}
1003479
public static PasswordManager getInstance(State state) {
    try {
      return CACHED_INSTANCES
          .get(new CachedInstanceKey(state));
    } catch (ExecutionException e) {
      throw new RuntimeException("Unable to get an instance of PasswordManager", e);
    }
  }
1251205
public com.google.protobuf.ByteString
      getStateBytes() {
    java.lang.Object ref = state_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      state_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
803183
@Override
	public InputStream getInputStream(final String key, final URI source, final MutableInt retLength)
			throws IOException {
		final String sourceMethod = "getInputStream"; //$NON-NLS-1$
		final boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(sourceClass, sourceMethod, new Object[] { key, source, retLength });
		}

		InputStream in = null, result = null;
		CacheEntry tryCacheEntry = (CacheEntry) super.get(key);
		URLConnection connection = source.toURL().openConnection();

		try {
			long lastModified = connection.getLastModified();
			if (tryCacheEntry != null) {
				// Make local copies of volatile CacheEntry fields
				byte[] bytes = tryCacheEntry.bytes;
				File file = tryCacheEntry.file;
				if (bytes != null) {
					// Important - CacheEntry.lastModified is set before CacheEntry.bytes so we can
					// safely
					// check CacheEntry.lastModified here even though we're not synchronized.
					if (lastModified != tryCacheEntry.lastModified) {
						// stale cache entry. Remove it and create a new one below
						cacheMap.remove(key, tryCacheEntry);
					} else {
						retLength.setValue(tryCacheEntry.bytes.length);
						result = new ByteArrayInputStream(tryCacheEntry.bytes);
					}
				} else if (file != null) {
					// Some platforms round file last modified times to nearest second.
					if (Math.abs(lastModified - file.lastModified()) > 1000) {
						// Stale cache entry, remove it and create a new one below
						cacheMap.remove(key, tryCacheEntry);
						// also delete the associated cache file asynchronously.
						cacheManager.deleteFileDelayed(file.getName());
					} else {
						try {
							retLength.setValue(file.length());
							result = new FileInputStream(file);
						} catch (FileNotFoundException ex) {
							// File doesn't exist (was probably deleted outside this program)
							// Not fatal, just fall through and create it again.
							cacheMap.remove(key, tryCacheEntry);
						}
					}
				}
				if (result != null) {
					// found result in cache. Return it.
					log.exiting(sourceClass, sourceMethod, result);
					return result;
				}
			}

			// Result not in cache (or we removed it). Try to create a new cache entry.
			CacheEntry newCacheEntry = new CacheEntry();
			CacheEntry oldCacheEntry = (CacheEntry) cacheMap.putIfAbsent(key, newCacheEntry);
			final CacheEntry cacheEntry = oldCacheEntry != null ? oldCacheEntry : newCacheEntry;

			// Synchronize on the cache entry so that more than one thread won't try to create the
			// zipped content.
			synchronized (cacheEntry) {
				if (cacheEntry.ex != null) {
					// An exception occurred trying to create the gzip response in another thread.
					// Re-throw the exception here.
					throw cacheEntry.ex;
				}
				// First, check to make sure that another thread didn't beat us to the punch.
				// Even though we're synchronized on the cacheEntry object, cacheEntry.bytes can be
				// cleared by the createCacheFileAsync callback, so we need to copy this volatile
				// field
				// to a local variable and access it from there.
				byte[] bytes = cacheEntry.bytes;
				if (bytes != null) {
					retLength.setValue(bytes.length);
					result = new ByteArrayInputStream(bytes);
				} else if (cacheEntry.file != null) { // once set, cacheEntry.file does not change
														// by convention
					retLength.setValue(cacheEntry.file.length());
					result = new FileInputStream(cacheEntry.file);
				} else {
					// Gzip encode the resource and save the result in the cache entry until the
					// cache
					// file is written asynchronously.
					try {
						in = connection.getInputStream();
						ByteArrayOutputStream bos = new ByteArrayOutputStream();
						VariableGZIPOutputStream compress = new VariableGZIPOutputStream(bos, 10240);
						compress.setLevel(Deflater.BEST_COMPRESSION);
						CopyUtil.copy(in, compress);

						// Important - CacheEntry.lastModified must be set before cacheEntry.bytes
						cacheEntry.lastModified = lastModified;
						cacheEntry.bytes = bos.toByteArray();
						result = new ByteArrayInputStream(cacheEntry.bytes);
						retLength.setValue(cacheEntry.bytes.length);

						// Call the cache manager to asynchronously save the gzipped response to
						// disk
						// Include the filename part of the source URI in the cached filename
						String path = source.getPath();
						int idx = path.lastIndexOf("/"); //$NON-NLS-1$
						String fname = (idx != -1) ? path.substring(idx + 1) : path;
						cacheManager.createCacheFileAsync(
								fname + ".gzip.", //$NON-NLS-1$
								new ByteArrayInputStream(cacheEntry.bytes),
								new ICacheManager.CreateCompletionCallback() {
									@Override
									public void completed(String filename, Exception e) {
										if (e != null && log.isLoggable(Level.SEVERE)) {
											// Exception occurred saving file. Not much we can do
											// except log the error
											log.logp(Level.SEVERE, sourceClass, sourceMethod,
													e.getMessage(), e);
											return;
										}
										File cacheFile = new File(cacheManager.getCacheDir(),
												filename);
										cacheFile.setLastModified(cacheEntry.lastModified);
										// Important - cacheEntry.file must be set before clearing
										// cacheEntry.bytes
										cacheEntry.file = cacheFile;
										cacheEntry.bytes = null;
									}
								});
					} catch (Throwable t) {
						cacheEntry.ex = (t instanceof IOException) ? (IOException) t
								: new IOException(t);
						cacheMap.remove(key, cacheEntry);
						throw cacheEntry.ex;
					}
				}
			}
		} finally {
			// URLConnection doesn't have a close method. The only way to make sure a connection is
			// closed is to close the input or output stream which is obtained from the connection.
			if (in != null) {
				in.close();
			} else {
				connection.getInputStream().close();
			}
		}
		if (isTraceLogging) {
			log.exiting(sourceClass, sourceClass, result);
		}
		return result;
	}
938316
public JsonElement getLowWatermark() {
    if (!contains(ConfigurationKeys.WATERMARK_INTERVAL_VALUE_KEY)) {
      return null;
    }
    return JSON_PARSER.parse(getProp(ConfigurationKeys.WATERMARK_INTERVAL_VALUE_KEY)).getAsJsonObject()
        .get(WatermarkInterval.LOW_WATERMARK_TO_JSON_KEY);
  }
1280846
public byte[] getFingerprintFromInputStream(InputStream inputStream) {
        byte[] fingerprint = null;
        try {
            fingerprint = new byte[inputStream.available()];
            inputStream.read(fingerprint);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fingerprint;
    }
462567
public static InputStream getResourceAsStream(String fileName) throws FileNotFoundException {
    String localPath = UI_DIR + fileName;
    String altLocalPath = INTERNAL_BUILD_UI_DIR + fileName;
    InputStream in = StaticContentHandler.class.getResourceAsStream(localPath);
    if (in == null) {
      in = StaticContentHandler.class.getResourceAsStream(altLocalPath);
    }
    if (in == null) {
      throw new FileNotFoundException(localPath + " <or> " + altLocalPath);
    }
    return in;
  }
428809
private long getLowWaterMark(Iterable<WorkUnitState> previousStates, String lowWaterMark) {

    long lowWaterMarkValue = retriever.getWatermarkFromString(lowWaterMark);

    // Find the max HWM from the previous states, this is the new current LWM
    for (WorkUnitState previousState : previousStates) {
      if (previousState.getWorkingState().equals(WorkUnitState.WorkingState.COMMITTED)) {
        long previousHighWaterMark = previousState.getWorkunit().getHighWaterMark();
        if (previousHighWaterMark > lowWaterMarkValue) {
          lowWaterMarkValue = previousHighWaterMark;
        }
      }
    }

    return lowWaterMarkValue + getRetriever().getWatermarkIncrementMs();
  }
462853
public long copyFileToImpl(OutputStream dest, long skip) throws FileNotFoundException, CopyFileToException {
        long result;

        try (InputStream src = newInputStream()) {
            if (skip(src, skip)) {
                return 0;
            }
            result = getWorld().getBuffer().copy(src, dest);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw new CopyFileToException(this, e);
        }
        return result;
    }
269628
public void cloneActionState(final ActionState source, final ActionState target) {
        source.getActionList().forEach(a -> target.getActionList().add(a));
        source.getExitActionList().forEach(a -> target.getExitActionList().add(a));
        source.getAttributes().asMap().forEach((k, v) -> target.getAttributes().put(k, v));
        source.getTransitionSet().forEach(t -> target.getTransitionSet().addAll(t));
        val field = ReflectionUtils.findField(target.getExceptionHandlerSet().getClass(), "exceptionHandlers");
        ReflectionUtils.makeAccessible(field);
        val list = (List<FlowExecutionExceptionHandler>) ReflectionUtils.getField(field, target.getExceptionHandlerSet());
        list.forEach(h -> source.getExceptionHandlerSet().add(h));
        target.setDescription(source.getDescription());
        target.setCaption(source.getCaption());
    }