text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../../../stylesheet.css" title="Style">

001
018package org.apache.hadoop.fs.http.server;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.fs.ContentSummary;
022import org.apache.hadoop.fs.FileChecksum;
023import org.apache.hadoop.fs.FileStatus;
024import org.apache.hadoop.fs.FileSystem;
025import org.apache.hadoop.fs.GlobFilter;
026import org.apache.hadoop.fs.Path;
027import org.apache.hadoop.fs.PathFilter;
028import org.apache.hadoop.fs.XAttrCodec;
029import org.apache.hadoop.fs.XAttrSetFlag;
030import org.apache.hadoop.fs.http.client.HttpFSFileSystem;
031import org.apache.hadoop.fs.permission.AclEntry;
032import org.apache.hadoop.fs.permission.AclStatus;
033import org.apache.hadoop.fs.permission.FsPermission;
034import org.apache.hadoop.hdfs.protocol.AclException;
035import org.apache.hadoop.io.IOUtils;
036import org.apache.hadoop.lib.service.FileSystemAccess;
037import org.json.simple.JSONArray;
038import org.json.simple.JSONObject;
039
040import java.io.IOException;
041import java.io.InputStream;
042import java.io.OutputStream;
043import java.util.EnumSet;
044import java.util.LinkedHashMap;
045import java.util.List;
046import java.util.Map;
047import java.util.Map.Entry;
048
049/**
050 * FileSystem operation executors used by {@link HttpFSServer}.
051 */
052@InterfaceAudience.Private
053public class FSOperations {
054
055  /**
056   * This class is used to group a FileStatus and an AclStatus together.
057   * It's needed for the GETFILESTATUS and LISTSTATUS calls, which take
058   * most info from the FileStatus and a wee bit from the AclStatus.
059   */
060  private static class StatusPair {
061    private FileStatus fileStatus;
062    private AclStatus aclStatus;
063
064    /**
065     * Simple constructor
066     * @param fileStatus Existing FileStatus object
067     * @param aclStatus Existing AclStatus object
068     */
069    public StatusPair(FileStatus fileStatus, AclStatus aclStatus) {
070      this.fileStatus = fileStatus;
071      this.aclStatus = aclStatus;
072    }
073
074    /**
075     * Create one StatusPair by performing the underlying calls to
076     * fs.getFileStatus and fs.getAclStatus
077     * @param fs The FileSystem where 'path' lives
078     * @param path The file/directory to query
079     * @throws IOException
080     */
081    public StatusPair(FileSystem fs, Path path) throws IOException {
082      fileStatus = fs.getFileStatus(path);
083      aclStatus = null;
084      try {
085        aclStatus = fs.getAclStatus(path);
086      } catch (AclException e) {
087        /*
088         * The cause is almost certainly an "ACLS aren't enabled"
089         * exception, so leave aclStatus at null and carry on.
090         */
091      } catch (UnsupportedOperationException e) {
092        /* Ditto above - this is the case for a local file system */
093      }
094    }
095
096    /**
097     * Return a Map suitable for conversion into JSON format
098     * @return The JSONish Map
099     */
100    public Map<String,Object> toJson() {
101      Map<String,Object> json = new LinkedHashMap<String,Object>();
102      json.put(HttpFSFileSystem.FILE_STATUS_JSON, toJsonInner(true));
103      return json;
104    }
105
106    /**
107     * Return in inner part of the JSON for the status - used by both the
108     * GETFILESTATUS and LISTSTATUS calls.
109     * @param emptyPathSuffix Whether or not to include PATH_SUFFIX_JSON
110     * @return The JSONish Map
111     */
112    public Map<String,Object> toJsonInner(boolean emptyPathSuffix) {
113      Map<String,Object> json = new LinkedHashMap<String,Object>();
114      json.put(HttpFSFileSystem.PATH_SUFFIX_JSON,
115              (emptyPathSuffix) ? "" : fileStatus.getPath().getName());
116      json.put(HttpFSFileSystem.TYPE_JSON,
117              HttpFSFileSystem.FILE_TYPE.getType(fileStatus).toString());
118      json.put(HttpFSFileSystem.LENGTH_JSON, fileStatus.getLen());
119      json.put(HttpFSFileSystem.OWNER_JSON, fileStatus.getOwner());
120      json.put(HttpFSFileSystem.GROUP_JSON, fileStatus.getGroup());
121      json.put(HttpFSFileSystem.PERMISSION_JSON,
122              HttpFSFileSystem.permissionToString(fileStatus.getPermission()));
123      json.put(HttpFSFileSystem.ACCESS_TIME_JSON, fileStatus.getAccessTime());
124      json.put(HttpFSFileSystem.MODIFICATION_TIME_JSON,
125              fileStatus.getModificationTime());
126      json.put(HttpFSFileSystem.BLOCK_SIZE_JSON, fileStatus.getBlockSize());
127      json.put(HttpFSFileSystem.REPLICATION_JSON, fileStatus.getReplication());
128      if ( (aclStatus != null) && !(aclStatus.getEntries().isEmpty()) ) {
129        json.put(HttpFSFileSystem.ACL_BIT_JSON,true);
130      }
131      return json;
132    }
133  }
134
135  /**
136   * Simple class used to contain and operate upon a list of StatusPair
137   * objects.  Used by LISTSTATUS.
138   */
139  private static class StatusPairs {
140    private StatusPair[] statusPairs;
141
142    /**
143     * Construct a list of StatusPair objects
144     * @param fs The FileSystem where 'path' lives
145     * @param path The directory to query
146     * @param filter A possible filter for entries in the directory
147     * @throws IOException
148     */
149    public StatusPairs(FileSystem fs, Path path, PathFilter filter)
150            throws IOException {
151      /* Grab all the file statuses at once in an array */
152      FileStatus[] fileStatuses = fs.listStatus(path, filter);
153
154      /* We'll have an array of StatusPairs of the same length */
155      AclStatus aclStatus = null;
156      statusPairs = new StatusPair[fileStatuses.length];
157
158      /*
159       * For each FileStatus, attempt to acquire an AclStatus.  If the
160       * getAclStatus throws an exception, we assume that ACLs are turned
161       * off entirely and abandon the attempt.
162       */
163      boolean useAcls = true;   // Assume ACLs work until proven otherwise
164      for (int i = 0; i < fileStatuses.length; i++) {
165        if (useAcls) {
166          try {
167            aclStatus = fs.getAclStatus(fileStatuses[i].getPath());
168          } catch (AclException e) {
169            /* Almost certainly due to an "ACLs not enabled" exception */
170            aclStatus = null;
171            useAcls = false;
172          } catch (UnsupportedOperationException e) {
173            /* Ditto above - this is the case for a local file system */
174            aclStatus = null;
175            useAcls = false;
176          }
177        }
178        statusPairs[i] = new StatusPair(fileStatuses[i], aclStatus);
179      }
180    }
181
182    /**
183     * Return a Map suitable for conversion into JSON.
184     * @return A JSONish Map
185     */
186    @SuppressWarnings({"unchecked"})
187    public Map<String,Object> toJson() {
188      Map<String,Object> json = new LinkedHashMap<String,Object>();
189      Map<String,Object> inner = new LinkedHashMap<String,Object>();
190      JSONArray statuses = new JSONArray();
191      for (StatusPair s : statusPairs) {
192        statuses.add(s.toJsonInner(false));
193      }
194      inner.put(HttpFSFileSystem.FILE_STATUS_JSON, statuses);
195      json.put(HttpFSFileSystem.FILE_STATUSES_JSON, inner);
196      return json;
197    }
198  }
199
200  /** Converts an <code>AclStatus</code> object into a JSON object.
201   *
202   * @param aclStatus AclStatus object
203   *
204   * @return The JSON representation of the ACLs for the file
205   */
206  @SuppressWarnings({"unchecked"})
207  private static Map<String,Object> aclStatusToJSON(AclStatus aclStatus) {
208    Map<String,Object> json = new LinkedHashMap<String,Object>();
209    Map<String,Object> inner = new LinkedHashMap<String,Object>();
210    JSONArray entriesArray = new JSONArray();
211    inner.put(HttpFSFileSystem.OWNER_JSON, aclStatus.getOwner());
212    inner.put(HttpFSFileSystem.GROUP_JSON, aclStatus.getGroup());
213    inner.put(HttpFSFileSystem.ACL_STICKY_BIT_JSON, aclStatus.isStickyBit());
214    for ( AclEntry e : aclStatus.getEntries() ) {
215      entriesArray.add(e.toString());
216    }
217    inner.put(HttpFSFileSystem.ACL_ENTRIES_JSON, entriesArray);
218    json.put(HttpFSFileSystem.ACL_STATUS_JSON, inner);
219    return json;
220  }
221
222  /**
223   * Converts a <code>FileChecksum</code> object into a JSON array
224   * object.
225   *
226   * @param checksum file checksum.
227   *
228   * @return The JSON representation of the file checksum.
229   */
230  @SuppressWarnings({"unchecked"})
231  private static Map fileChecksumToJSON(FileChecksum checksum) {
232    Map json = new LinkedHashMap();
233    json.put(HttpFSFileSystem.CHECKSUM_ALGORITHM_JSON, checksum.getAlgorithmName());
234    json.put(HttpFSFileSystem.CHECKSUM_BYTES_JSON,
235             org.apache.hadoop.util.StringUtils.byteToHexString(checksum.getBytes()));
236    json.put(HttpFSFileSystem.CHECKSUM_LENGTH_JSON, checksum.getLength());
237    Map response = new LinkedHashMap();
238    response.put(HttpFSFileSystem.FILE_CHECKSUM_JSON, json);
239    return response;
240  }
241
242  /**
243   * Converts xAttrs to a JSON object.
244   *
245   * @param xAttrs file xAttrs.
246   * @param encoding format of xattr values.
247   *
248   * @return The JSON representation of the xAttrs.
249   * @throws IOException
250   */
251  @SuppressWarnings({"unchecked", "rawtypes"})
252  private static Map xAttrsToJSON(Map<String, byte[]> xAttrs,
253      XAttrCodec encoding) throws IOException {
254    Map jsonMap = new LinkedHashMap();
255    JSONArray jsonArray = new JSONArray();
256    if (xAttrs != null) {
257      for (Entry<String, byte[]> e : xAttrs.entrySet()) {
258        Map json = new LinkedHashMap();
259        json.put(HttpFSFileSystem.XATTR_NAME_JSON, e.getKey());
260        if (e.getValue() != null) {
261          json.put(HttpFSFileSystem.XATTR_VALUE_JSON,
262              XAttrCodec.encodeValue(e.getValue(), encoding));
263        }
264        jsonArray.add(json);
265      }
266    }
267    jsonMap.put(HttpFSFileSystem.XATTRS_JSON, jsonArray);
268    return jsonMap;
269  }
270
271  /**
272   * Converts xAttr names to a JSON object.
273   *
274   * @param names file xAttr names.
275   *
276   * @return The JSON representation of the xAttr names.
277   * @throws IOException
278   */
279  @SuppressWarnings({"unchecked", "rawtypes"})
280  private static Map xAttrNamesToJSON(List<String> names) throws IOException {
281    Map jsonMap = new LinkedHashMap();
282    jsonMap.put(HttpFSFileSystem.XATTRNAMES_JSON, JSONArray.toJSONString(names));
283    return jsonMap;
284  }
285
286  /**
287   * Converts a <code>ContentSummary</code> object into a JSON array
288   * object.
289   *
290   * @param contentSummary the content summary
291   *
292   * @return The JSON representation of the content summary.
293   */
294  @SuppressWarnings({"unchecked"})
295  private static Map contentSummaryToJSON(ContentSummary contentSummary) {
296    Map json = new LinkedHashMap();
297    json.put(HttpFSFileSystem.CONTENT_SUMMARY_DIRECTORY_COUNT_JSON, contentSummary.getDirectoryCount());
298    json.put(HttpFSFileSystem.CONTENT_SUMMARY_FILE_COUNT_JSON, contentSummary.getFileCount());
299    json.put(HttpFSFileSystem.CONTENT_SUMMARY_LENGTH_JSON, contentSummary.getLength());
300    json.put(HttpFSFileSystem.CONTENT_SUMMARY_QUOTA_JSON, contentSummary.getQuota());
301    json.put(HttpFSFileSystem.CONTENT_SUMMARY_SPACE_CONSUMED_JSON, contentSummary.getSpaceConsumed());
302    json.put(HttpFSFileSystem.CONTENT_SUMMARY_SPACE_QUOTA_JSON, contentSummary.getSpaceQuota());
303    Map response = new LinkedHashMap();
304    response.put(HttpFSFileSystem.CONTENT_SUMMARY_JSON, json);
305    return response;
306  }
307
308  /**
309   * Converts an object into a Json Map with with one key-value entry.
310   * <p/>
311   * It assumes the given value is either a JSON primitive type or a
312   * <code>JsonAware</code> instance.
313   *
314   * @param name name for the key of the entry.
315   * @param value for the value of the entry.
316   *
317   * @return the JSON representation of the key-value pair.
318   */
319  @SuppressWarnings("unchecked")
320  private static JSONObject toJSON(String name, Object value) {
321    JSONObject json = new JSONObject();
322    json.put(name, value);
323    return json;
324  }
325
326  /**
327   * Executor that performs an append FileSystemAccess files system operation.
328   */
329  @InterfaceAudience.Private
330  public static class FSAppend implements FileSystemAccess.FileSystemExecutor<Void> {
331    private InputStream is;
332    private Path path;
333
334    /**
335     * Creates an Append executor.
336     *
337     * @param is input stream to append.
338     * @param path path of the file to append.
339     */
340    public FSAppend(InputStream is, String path) {
341      this.is = is;
342      this.path = new Path(path);
343    }
344
345    /**
346     * Executes the filesystem operation.
347     *
348     * @param fs filesystem instance to use.
349     *
350     * @return void.
351     *
352     * @throws IOException thrown if an IO error occured.
353     */
354    @Override
355    public Void execute(FileSystem fs) throws IOException {
356      int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096);
357      OutputStream os = fs.append(path, bufferSize);
358      IOUtils.copyBytes(is, os, bufferSize, true);
359      os.close();
360      return null;
361    }
362
363  }
364
365  /**
366   * Executor that performs an append FileSystemAccess files system operation.
367   */
368  @InterfaceAudience.Private
369  public static class FSConcat implements FileSystemAccess.FileSystemExecutor<Void> {
370    private Path path;
371    private Path[] sources;
372
373    /**
374     * Creates a Concat executor.
375     *
376     * @param path target path to concat to.
377     * @param sources comma seperated absolute paths to use as sources.
378     */
379    public FSConcat(String path, String[] sources) {
380      this.sources = new Path[sources.length];
381
382      for(int i = 0; i < sources.length; i++) {
383        this.sources[i] = new Path(sources[i]);
384      }
385
386      this.path = new Path(path);
387    }
388
389    /**
390     * Executes the filesystem operation.
391     *
392     * @param fs filesystem instance to use.
393     *
394     * @return void.
395     *
396     * @throws IOException thrown if an IO error occured.
397     */
398    @Override
399    public Void execute(FileSystem fs) throws IOException {
400      fs.concat(path, sources);
401      return null;
402    }
403
404  }
405
406  /**
407   * Executor that performs a content-summary FileSystemAccess files system operation.
408   */
409  @InterfaceAudience.Private
410  public static class FSContentSummary implements FileSystemAccess.FileSystemExecutor<Map> {
411    private Path path;
412
413    /**
414     * Creates a content-summary executor.
415     *
416     * @param path the path to retrieve the content-summary.
417     */
418    public FSContentSummary(String path) {
419      this.path = new Path(path);
420    }
421
422    /**
423     * Executes the filesystem operation.
424     *
425     * @param fs filesystem instance to use.
426     *
427     * @return a Map object (JSON friendly) with the content-summary.
428     *
429     * @throws IOException thrown if an IO error occured.
430     */
431    @Override
432    public Map execute(FileSystem fs) throws IOException {
433      ContentSummary contentSummary = fs.getContentSummary(path);
434      return contentSummaryToJSON(contentSummary);
435    }
436
437  }
438
439  /**
440   * Executor that performs a create FileSystemAccess files system operation.
441   */
442  @InterfaceAudience.Private
443  public static class FSCreate implements FileSystemAccess.FileSystemExecutor<Void> {
444    private InputStream is;
445    private Path path;
446    private short permission;
447    private boolean override;
448    private short replication;
449    private long blockSize;
450
451    /**
452     * Creates a Create executor.
453     *
454     * @param is input stream to for the file to create.
455     * @param path path of the file to create.
456     * @param perm permission for the file.
457     * @param override if the file should be overriden if it already exist.
458     * @param repl the replication factor for the file.
459     * @param blockSize the block size for the file.
460     */
461    public FSCreate(InputStream is, String path, short perm, boolean override,
462                    short repl, long blockSize) {
463      this.is = is;
464      this.path = new Path(path);
465      this.permission = perm;
466      this.override = override;
467      this.replication = repl;
468      this.blockSize = blockSize;
469    }
470
471    /**
472     * Executes the filesystem operation.
473     *
474     * @param fs filesystem instance to use.
475     *
476     * @return The URI of the created file.
477     *
478     * @throws IOException thrown if an IO error occured.
479     */
480    @Override
481    public Void execute(FileSystem fs) throws IOException {
482      if (replication == -1) {
483        replication = fs.getDefaultReplication(path);
484      }
485      if (blockSize == -1) {
486        blockSize = fs.getDefaultBlockSize(path);
487      }
488      FsPermission fsPermission = new FsPermission(permission);
489      int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096);
490      OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null);
491      IOUtils.copyBytes(is, os, bufferSize, true);
492      os.close();
493      return null;
494    }
495
496  }
497
498  /**
499   * Executor that performs a delete FileSystemAccess files system operation.
500   */
501  @InterfaceAudience.Private
502  public static class FSDelete implements FileSystemAccess.FileSystemExecutor<JSONObject> {
503    private Path path;
504    private boolean recursive;
505
506    /**
507     * Creates a Delete executor.
508     *
509     * @param path path to delete.
510     * @param recursive if the delete should be recursive or not.
511     */
512    public FSDelete(String path, boolean recursive) {
513      this.path = new Path(path);
514      this.recursive = recursive;
515    }
516
517    /**
518     * Executes the filesystem operation.
519     *
520     * @param fs filesystem instance to use.
521     *
522     * @return <code>true</code> if the delete operation was successful,
523     *         <code>false</code> otherwise.
524     *
525     * @throws IOException thrown if an IO error occured.
526     */
527    @Override
528    public JSONObject execute(FileSystem fs) throws IOException {
529      boolean deleted = fs.delete(path, recursive);
530      return toJSON(HttpFSFileSystem.DELETE_JSON.toLowerCase(), deleted);
531    }
532
533  }
534
535  /**
536   * Executor that performs a file-checksum FileSystemAccess files system operation.
537   */
538  @InterfaceAudience.Private
539  public static class FSFileChecksum implements FileSystemAccess.FileSystemExecutor<Map> {
540    private Path path;
541
542    /**
543     * Creates a file-checksum executor.
544     *
545     * @param path the path to retrieve the checksum.
546     */
547    public FSFileChecksum(String path) {
548      this.path = new Path(path);
549    }
550
551    /**
552     * Executes the filesystem operation.
553     *
554     * @param fs filesystem instance to use.
555     *
556     * @return a Map object (JSON friendly) with the file checksum.
557     *
558     * @throws IOException thrown if an IO error occured.
559     */
560    @Override
561    public Map execute(FileSystem fs) throws IOException {
562      FileChecksum checksum = fs.getFileChecksum(path);
563      return fileChecksumToJSON(checksum);
564    }
565
566  }
567
568  /**
569   * Executor that performs a file-status FileSystemAccess files system operation.
570   */
571  @InterfaceAudience.Private
572  public static class FSFileStatus implements FileSystemAccess.FileSystemExecutor<Map> {
573    private Path path;
574
575    /**
576     * Creates a file-status executor.
577     *
578     * @param path the path to retrieve the status.
579     */
580    public FSFileStatus(String path) {
581      this.path = new Path(path);
582    }
583
584    /**
585     * Executes the filesystem getFileStatus operation and returns the
586     * result in a JSONish Map.
587     *
588     * @param fs filesystem instance to use.
589     *
590     * @return a Map object (JSON friendly) with the file status.
591     *
592     * @throws IOException thrown if an IO error occurred.
593     */
594    @Override
595    public Map execute(FileSystem fs) throws IOException {
596      StatusPair sp = new StatusPair(fs, path);
597      return sp.toJson();
598    }
599
600  }
601
602  /**
603   * Executor that performs a home-dir FileSystemAccess files system operation.
604   */
605  @InterfaceAudience.Private
606  public static class FSHomeDir implements FileSystemAccess.FileSystemExecutor<JSONObject> {
607
608    /**
609     * Executes the filesystem operation.
610     *
611     * @param fs filesystem instance to use.
612     *
613     * @return a JSON object with the user home directory.
614     *
615     * @throws IOException thrown if an IO error occured.
616     */
617    @Override
618    @SuppressWarnings("unchecked")
619    public JSONObject execute(FileSystem fs) throws IOException {
620      Path homeDir = fs.getHomeDirectory();
621      JSONObject json = new JSONObject();
622      json.put(HttpFSFileSystem.HOME_DIR_JSON, homeDir.toUri().getPath());
623      return json;
624    }
625
626  }
627
628  /**
629   * Executor that performs a list-status FileSystemAccess files system operation.
630   */
631  @InterfaceAudience.Private
632  public static class FSListStatus implements FileSystemAccess.FileSystemExecutor<Map>, PathFilter {
633    private Path path;
634    private PathFilter filter;
635
636    /**
637     * Creates a list-status executor.
638     *
639     * @param path the directory to retrieve the status of its contents.
640     * @param filter glob filter to use.
641     *
642     * @throws IOException thrown if the filter expression is incorrect.
643     */
644    public FSListStatus(String path, String filter) throws IOException {
645      this.path = new Path(path);
646      this.filter = (filter == null) ? this : new GlobFilter(filter);
647    }
648
649    /**
650     * Returns data for a JSON Map containing the information for
651     * the set of files in 'path' that match 'filter'.
652     *
653     * @param fs filesystem instance to use.
654     *
655     * @return a Map with the file status of the directory
656     *         contents that match the filter
657     *
658     * @throws IOException thrown if an IO error occurred.
659     */
660    @Override
661    public Map execute(FileSystem fs) throws IOException {
662      StatusPairs sp = new StatusPairs(fs, path, filter);
663      return sp.toJson();
664    }
665
666    @Override
667    public boolean accept(Path path) {
668      return true;
669    }
670
671  }
672
673  /**
674   * Executor that performs a mkdirs FileSystemAccess files system operation.
675   */
676  @InterfaceAudience.Private
677  public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor<JSONObject> {
678
679    private Path path;
680    private short permission;
681
682    /**
683     * Creates a mkdirs executor.
684     *
685     * @param path directory path to create.
686     * @param permission permission to use.
687     */
688    public FSMkdirs(String path, short permission) {
689      this.path = new Path(path);
690      this.permission = permission;
691    }
692
693    /**
694     * Executes the filesystem operation.
695     *
696     * @param fs filesystem instance to use.
697     *
698     * @return <code>true</code> if the mkdirs operation was successful,
699     *         <code>false</code> otherwise.
700     *
701     * @throws IOException thrown if an IO error occured.
702     */
703    @Override
704    public JSONObject execute(FileSystem fs) throws IOException {
705      FsPermission fsPermission = new FsPermission(permission);
706      boolean mkdirs = fs.mkdirs(path, fsPermission);
707      return toJSON(HttpFSFileSystem.MKDIRS_JSON, mkdirs);
708    }
709
710  }
711
712  /**
713   * Executor that performs a open FileSystemAccess files system operation.
714   */
715  @InterfaceAudience.Private
716  public static class FSOpen implements FileSystemAccess.FileSystemExecutor<InputStream> {
717    private Path path;
718
719    /**
720     * Creates a open executor.
721     *
722     * @param path file to open.
723     */
724    public FSOpen(String path) {
725      this.path = new Path(path);
726    }
727
728    /**
729     * Executes the filesystem operation.
730     *
731     * @param fs filesystem instance to use.
732     *
733     * @return The inputstream of the file.
734     *
735     * @throws IOException thrown if an IO error occured.
736     */
737    @Override
738    public InputStream execute(FileSystem fs) throws IOException {
739      int bufferSize = HttpFSServerWebApp.get().getConfig().getInt("httpfs.buffer.size", 4096);
740      return fs.open(path, bufferSize);
741    }
742
743  }
744
745  /**
746   * Executor that performs a rename FileSystemAccess files system operation.
747   */
748  @InterfaceAudience.Private
749  public static class FSRename implements FileSystemAccess.FileSystemExecutor<JSONObject> {
750    private Path path;
751    private Path toPath;
752
753    /**
754     * Creates a rename executor.
755     *
756     * @param path path to rename.
757     * @param toPath new name.
758     */
759    public FSRename(String path, String toPath) {
760      this.path = new Path(path);
761      this.toPath = new Path(toPath);
762    }
763
764    /**
765     * Executes the filesystem operation.
766     *
767     * @param fs filesystem instance to use.
768     *
769     * @return <code>true</code> if the rename operation was successful,
770     *         <code>false</code> otherwise.
771     *
772     * @throws IOException thrown if an IO error occured.
773     */
774    @Override
775    public JSONObject execute(FileSystem fs) throws IOException {
776      boolean renamed = fs.rename(path, toPath);
777      return toJSON(HttpFSFileSystem.RENAME_JSON, renamed);
778    }
779
780  }
781
782  /**
783   * Executor that performs a set-owner FileSystemAccess files system operation.
784   */
785  @InterfaceAudience.Private
786  public static class FSSetOwner implements FileSystemAccess.FileSystemExecutor<Void> {
787    private Path path;
788    private String owner;
789    private String group;
790
791    /**
792     * Creates a set-owner executor.
793     *
794     * @param path the path to set the owner.
795     * @param owner owner to set.
796     * @param group group to set.
797     */
798    public FSSetOwner(String path, String owner, String group) {
799      this.path = new Path(path);
800      this.owner = owner;
801      this.group = group;
802    }
803
804    /**
805     * Executes the filesystem operation.
806     *
807     * @param fs filesystem instance to use.
808     *
809     * @return void.
810     *
811     * @throws IOException thrown if an IO error occured.
812     */
813    @Override
814    public Void execute(FileSystem fs) throws IOException {
815      fs.setOwner(path, owner, group);
816      return null;
817    }
818
819  }
820
821  /**
822   * Executor that performs a set-permission FileSystemAccess files system operation.
823   */
824  @InterfaceAudience.Private
825  public static class FSSetPermission implements FileSystemAccess.FileSystemExecutor<Void> {
826
827    private Path path;
828    private short permission;
829
830    /**
831     * Creates a set-permission executor.
832     *
833     * @param path path to set the permission.
834     * @param permission permission to set.
835     */
836    public FSSetPermission(String path, short permission) {
837      this.path = new Path(path);
838      this.permission = permission;
839    }
840
841    /**
842     * Executes the filesystem operation.
843     *
844     * @param fs filesystem instance to use.
845     *
846     * @return void.
847     *
848     * @throws IOException thrown if an IO error occured.
849     */
850    @Override
851    public Void execute(FileSystem fs) throws IOException {
852      FsPermission fsPermission = new FsPermission(permission);
853      fs.setPermission(path, fsPermission);
854      return null;
855    }
856
857  }
858
859  /**
860   * Executor that sets the acl for a file in a FileSystem
861   */
862  @InterfaceAudience.Private
863  public static class FSSetAcl implements FileSystemAccess.FileSystemExecutor<Void> {
864
865    private Path path;
866    private List<AclEntry> aclEntries;
867
868    /**
869     * Creates a set-acl executor.
870     *
871     * @param path path to set the acl.
872     * @param aclSpec acl to set.
873     */
874    public FSSetAcl(String path, String aclSpec) {
875      this.path = new Path(path);
876      this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
877    }
878
879    /**
880     * Executes the filesystem operation.
881     *
882     * @param fs filesystem instance to use.
883     *
884     * @return void.
885     *
886     * @throws IOException thrown if an IO error occurred.
887     */
888    @Override
889    public Void execute(FileSystem fs) throws IOException {
890      fs.setAcl(path, aclEntries);
891      return null;
892    }
893
894  }
895
896  /**
897   * Executor that removes all acls from a file in a FileSystem
898   */
899  @InterfaceAudience.Private
900  public static class FSRemoveAcl implements FileSystemAccess.FileSystemExecutor<Void> {
901
902    private Path path;
903
904    /**
905     * Creates a remove-acl executor.
906     *
907     * @param path path from which to remove the acl.
908     */
909    public FSRemoveAcl(String path) {
910      this.path = new Path(path);
911    }
912
913    /**
914     * Executes the filesystem operation.
915     *
916     * @param fs filesystem instance to use.
917     *
918     * @return void.
919     *
920     * @throws IOException thrown if an IO error occurred.
921     */
922    @Override
923    public Void execute(FileSystem fs) throws IOException {
924      fs.removeAcl(path);
925      return null;
926    }
927
928  }
929
930  /**
931   * Executor that modifies acl entries for a file in a FileSystem
932   */
933  @InterfaceAudience.Private
934  public static class FSModifyAclEntries implements FileSystemAccess.FileSystemExecutor<Void> {
935
936    private Path path;
937    private List<AclEntry> aclEntries;
938
939    /**
940     * Creates a modify-acl executor.
941     *
942     * @param path path to set the acl.
943     * @param aclSpec acl to set.
944     */
945    public FSModifyAclEntries(String path, String aclSpec) {
946      this.path = new Path(path);
947      this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
948    }
949
950    /**
951     * Executes the filesystem operation.
952     *
953     * @param fs filesystem instance to use.
954     *
955     * @return void.
956     *
957     * @throws IOException thrown if an IO error occurred.
958     */
959    @Override
960    public Void execute(FileSystem fs) throws IOException {
961      fs.modifyAclEntries(path, aclEntries);
962      return null;
963    }
964
965  }
966
967  /**
968   * Executor that removes acl entries from a file in a FileSystem
969   */
970  @InterfaceAudience.Private
971  public static class FSRemoveAclEntries implements FileSystemAccess.FileSystemExecutor<Void> {
972
973    private Path path;
974    private List<AclEntry> aclEntries;
975
976    /**
977     * Creates a remove acl entry executor.
978     *
979     * @param path path to set the acl.
980     * @param aclSpec acl parts to remove.
981     */
982    public FSRemoveAclEntries(String path, String aclSpec) {
983      this.path = new Path(path);
984      this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
985    }
986
987    /**
988     * Executes the filesystem operation.
989     *
990     * @param fs filesystem instance to use.
991     *
992     * @return void.
993     *
994     * @throws IOException thrown if an IO error occurred.
995     */
996    @Override
997    public Void execute(FileSystem fs) throws IOException {
998      fs.removeAclEntries(path, aclEntries);
999      return null;
1000    }
1001
1002  }
1003
1004  /**
1005   * Executor that removes the default acl from a directory in a FileSystem
1006   */
1007  @InterfaceAudience.Private
1008  public static class FSRemoveDefaultAcl implements FileSystemAccess.FileSystemExecutor<Void> {
1009
1010    private Path path;
1011
1012    /**
1013     * Creates an executor for removing the default acl.
1014     *
1015     * @param path path to set the acl.
1016     */
1017    public FSRemoveDefaultAcl(String path) {
1018      this.path = new Path(path);
1019    }
1020
1021    /**
1022     * Executes the filesystem operation.
1023     *
1024     * @param fs filesystem instance to use.
1025     *
1026     * @return void.
1027     *
1028     * @throws IOException thrown if an IO error occurred.
1029     */
1030    @Override
1031    public Void execute(FileSystem fs) throws IOException {
1032      fs.removeDefaultAcl(path);
1033      return null;
1034    }
1035
1036  }
1037
1038  /**
1039   * Executor that gets the ACL information for a given file.
1040   */
1041  @InterfaceAudience.Private
1042  public static class FSAclStatus implements FileSystemAccess.FileSystemExecutor<Map> {
1043    private Path path;
1044
1045    /**
1046     * Creates an executor for getting the ACLs for a file.
1047     *
1048     * @param path the path to retrieve the ACLs.
1049     */
1050    public FSAclStatus(String path) {
1051      this.path = new Path(path);
1052    }
1053
1054    /**
1055     * Executes the filesystem operation.
1056     *
1057     * @param fs filesystem instance to use.
1058     *
1059     * @return a Map object (JSON friendly) with the file status.
1060     *
1061     * @throws IOException thrown if an IO error occurred.
1062     */
1063    @Override
1064    public Map execute(FileSystem fs) throws IOException {
1065      AclStatus status = fs.getAclStatus(path);
1066      return aclStatusToJSON(status);
1067    }
1068
1069  }
1070
1071  /**
1072   * Executor that performs a set-replication FileSystemAccess files system operation.
1073   */
1074  @InterfaceAudience.Private
1075  public static class FSSetReplication implements FileSystemAccess.FileSystemExecutor<JSONObject> {
1076    private Path path;
1077    private short replication;
1078
1079    /**
1080     * Creates a set-replication executor.
1081     *
1082     * @param path path to set the replication factor.
1083     * @param replication replication factor to set.
1084     */
1085    public FSSetReplication(String path, short replication) {
1086      this.path = new Path(path);
1087      this.replication = replication;
1088    }
1089
1090    /**
1091     * Executes the filesystem operation.
1092     *
1093     * @param fs filesystem instance to use.
1094     *
1095     * @return <code>true</code> if the replication value was set,
1096     *         <code>false</code> otherwise.
1097     *
1098     * @throws IOException thrown if an IO error occured.
1099     */
1100    @Override
1101    @SuppressWarnings("unchecked")
1102    public JSONObject execute(FileSystem fs) throws IOException {
1103      boolean ret = fs.setReplication(path, replication);
1104      JSONObject json = new JSONObject();
1105      json.put(HttpFSFileSystem.SET_REPLICATION_JSON, ret);
1106      return json;
1107    }
1108
1109  }
1110
1111  /**
1112   * Executor that performs a set-times FileSystemAccess files system operation.
1113   */
1114  @InterfaceAudience.Private
1115  public static class FSSetTimes implements FileSystemAccess.FileSystemExecutor<Void> {
1116    private Path path;
1117    private long mTime;
1118    private long aTime;
1119
1120    /**
1121     * Creates a set-times executor.
1122     *
1123     * @param path path to set the times.
1124     * @param mTime modified time to set.
1125     * @param aTime access time to set.
1126     */
1127    public FSSetTimes(String path, long mTime, long aTime) {
1128      this.path = new Path(path);
1129      this.mTime = mTime;
1130      this.aTime = aTime;
1131    }
1132
1133    /**
1134     * Executes the filesystem operation.
1135     *
1136     * @param fs filesystem instance to use.
1137     *
1138     * @return void.
1139     *
1140     * @throws IOException thrown if an IO error occured.
1141     */
1142    @Override
1143    public Void execute(FileSystem fs) throws IOException {
1144      fs.setTimes(path, mTime, aTime);
1145      return null;
1146    }
1147
1148  }
1149
1150  /**
1151   * Executor that performs a setxattr FileSystemAccess files system operation.
1152   */
1153  @InterfaceAudience.Private
1154  public static class FSSetXAttr implements
1155      FileSystemAccess.FileSystemExecutor<Void> {
1156
1157    private Path path;
1158    private String name;
1159    private byte[] value;
1160    private EnumSet<XAttrSetFlag> flag;
1161
1162    public FSSetXAttr(String path, String name, String encodedValue,
1163        EnumSet<XAttrSetFlag> flag) throws IOException {
1164      this.path = new Path(path);
1165      this.name = name;
1166      this.value = XAttrCodec.decodeValue(encodedValue);
1167      this.flag = flag;
1168    }
1169
1170    @Override
1171    public Void execute(FileSystem fs) throws IOException {
1172      fs.setXAttr(path, name, value, flag);
1173      return null;
1174    }
1175  }
1176
1177  /**
1178   * Executor that performs a removexattr FileSystemAccess files system
1179   * operation.
1180   */
1181  @InterfaceAudience.Private
1182  public static class FSRemoveXAttr implements
1183      FileSystemAccess.FileSystemExecutor<Void> {
1184
1185    private Path path;
1186    private String name;
1187
1188    public FSRemoveXAttr(String path, String name) {
1189      this.path = new Path(path);
1190      this.name = name;
1191    }
1192
1193    @Override
1194    public Void execute(FileSystem fs) throws IOException {
1195      fs.removeXAttr(path, name);
1196      return null;
1197    }
1198  }
1199
1200  /**
1201   * Executor that performs listing xattrs FileSystemAccess files system
1202   * operation.
1203   */
1204  @SuppressWarnings("rawtypes")
1205  @InterfaceAudience.Private
1206  public static class FSListXAttrs implements
1207      FileSystemAccess.FileSystemExecutor<Map> {
1208    private Path path;
1209
1210    /**
1211     * Creates listing xattrs executor.
1212     *
1213     * @param path the path to retrieve the xattrs.
1214     */
1215    public FSListXAttrs(String path) {
1216      this.path = new Path(path);
1217    }
1218
1219    /**
1220     * Executes the filesystem operation.
1221     *
1222     * @param fs filesystem instance to use.
1223     *
1224     * @return Map a map object (JSON friendly) with the xattr names.
1225     *
1226     * @throws IOException thrown if an IO error occured.
1227     */
1228    @Override
1229    public Map execute(FileSystem fs) throws IOException {
1230      List<String> names = fs.listXAttrs(path);
1231      return xAttrNamesToJSON(names);
1232    }
1233  }
1234
1235  /**
1236   * Executor that performs getting xattrs FileSystemAccess files system
1237   * operation.
1238   */
1239  @SuppressWarnings("rawtypes")
1240  @InterfaceAudience.Private
1241  public static class FSGetXAttrs implements
1242      FileSystemAccess.FileSystemExecutor<Map> {
1243    private Path path;
1244    private List<String> names;
1245    private XAttrCodec encoding;
1246
1247    /**
1248     * Creates getting xattrs executor.
1249     *
1250     * @param path the path to retrieve the xattrs.
1251     */
1252    public FSGetXAttrs(String path, List<String> names, XAttrCodec encoding) {
1253      this.path = new Path(path);
1254      this.names = names;
1255      this.encoding = encoding;
1256    }
1257
1258    /**
1259     * Executes the filesystem operation.
1260     *
1261     * @param fs filesystem instance to use.
1262     *
1263     * @return Map a map object (JSON friendly) with the xattrs.
1264     *
1265     * @throws IOException thrown if an IO error occured.
1266     */
1267    @Override
1268    public Map execute(FileSystem fs) throws IOException {
1269      Map<String, byte[]> xattrs = null;
1270      if (names != null && !names.isEmpty()) {
1271        xattrs = fs.getXAttrs(path, names);
1272      } else {
1273        xattrs = fs.getXAttrs(path);
1274      }
1275      return xAttrsToJSON(xattrs, encoding);
1276    }
1277  }
1278}


text:
<?php

final class PhabricatorPasteSnippet extends Phobject {

  const FULL = 'full';
  const FIRST_LINES = 'first_lines';
  const FIRST_BYTES = 'first_bytes';

  private $content;
  private $type;

  public function __construct($content, $type) {
    $this->content = $content;
    $this->type = $type;
  }

  public function getContent() {
    return $this->content;
  }

  public function getType() {
    return $this->type;
  }
}

redpajama_set_name: RedPajamaGithub


text:
import React from 'react';
import {
  Text,
  View,
  StyleSheet,
  TextInput,
  AsyncStorage,
  Image,
  TouchableNativeFeedback,
} from 'react-native';
import { Container, Content, Spinner } from 'native-base';
import ScrollableTabView, { DefaultTabBar } from 'react-native-scrollable-tab-view';
import OneSignal from 'react-native-onesignal';
import API from '../services/API/API';
import SessionUser from '../state/SessionUser';
import WalletService from '../services/WalletService';
import MoneyRequestScreen from './MoneyRequestScreen';
import List from './List';

import Constants from '../components/Constants';

const applicationAsyncInit = async function() {
  try {
    const user = await SessionUser.loadUser();
    let userData
    if(!user) {
      console.log("Creating user")
      const wallet = WalletService.generateNewWallet();
      await SessionUser.saveUser(wallet);
      userData = await API.user.register('username', 'password', wallet.address,  wallet.address)
    } else {
      userData = await API.user.getUserData(user.address);
    }
    console.log("Loaded User", SessionUser.getUser())
  } catch(error) {
    console.log("[App.onApplicationInit] cannot create a new user", error);
  }
};

export default class HomeScreen extends React.Component {

  constructor() {
    super();
    this.state = {
      userLoaded: false
    }
  }

  static navigationOptions = {
    header: null,
  }

  componentWillMount() {
    applicationAsyncInit().then(() => this.setState({userLoaded: true}));
  }

  render() {
    if(this.state.userLoaded) {
      return (
        <View style={styles.container}>
          <ScrollableTabView
            tabBarActiveTextColor='#ffc211'
            tabBarUnderlineStyle={{ backgroundColor: '#ffc211'}}
            renderTabBar={() => <DefaultTabBar />}
            tabBarPosition='bottom'
          >
            <MoneyRequestScreen tabLabel="Request" />
            <List navigation={this.props.navigation} tabLabel="List"/>
          </ScrollableTabView>
        </View>
      );
    } else {
       return (
        <View style={styles.container}>
          <View style={styles.firstRow} />
          <View style={styles.secondRow}>
            <Image
              style={{
                resizeMode: 'contain',
                width: Constants.realWidth * (9 / 10)
              }}
              source={require('../images/humanATM_png.png')}
            />
          </View>
          <View style={styles.thirdRow}>
            <Spinner />
          </View>
        </View>
       )
    }
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    width: Constants.realWidth,
    height: Constants.realHeight,
    alignContent: 'center',
  },
  firstRow: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    height: (Constants.realHeight - Constants.tabviewHeight) / 3
  },
  secondRow: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    height: (Constants.realHeight - Constants.tabviewHeight) / 3
  },
  thirdRow: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    height: (Constants.realHeight - Constants.tabviewHeight) / 3
  },
});


text:
<?php
	#
	# $Id: ports-ignore.php,v 1.2 2006-12-17 12:06:15 dan Exp $
	#
	# Copyright (c) 1998-2004 DVL Software Limited
	#

	require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/common.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/freshports.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php');
?>

FreshPorts Conflict Matches

This page is manually generated and was last updated at:

Please look for the ports you maintain, and verify the conflicts are what you expect.  The middle column is the port you maintain. The right hand column are the conflicts.

Please report any issues to dvl@FreeBSD.org

<?php

$sql = "
SELECT distinct P.maintainer, C.name || '/' || E.name AS port_name, f.*
  FROM ports_conflicts_matches PCM
  JOIN ports_conflicts PC ON PCM.ports_conflicts_id = PC.id
  JOIN GetPortFromPackageName(PackageName(PCM.port_id)) AS f ON true
  JOIN ports           P  ON PC.port_id    = P.id
  JOIN element         E  ON P.element_id  = E.id
  JOIN categories      C  ON P.category_id = C.id
 WHERE coalesce(P.conflicts, P.conflicts_build, P.conflicts_install) IS NOT NULL order by 1, 2";

echo "
$sql
";

$result = pg_exec($db, $sql);
if (!$result) {
  echo pg_last_error($db);
  die('that did not work');
}
$numrows = pg_num_rows($result);
echo '

Maintainer	port	conflicts with
';
for ($i = 0; $i < $numrows; $i++) {
	 $myrow = pg_fetch_array($result, $i);
	 echo '
' . $myrow['maintainer'] . '	' .  $myrow['port_name'] .
              '	conflicts with: ' . $myrow['category'] . '/' . $myrow['port'] . '
';
}

echo '
';


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Verrucaria lamprocarpa Stirt.

### Remarks
null


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Friesia 11: 108 (1976)

#### Original name
Xenolachne longicornis Hauerslev, 1976

### Remarks
null


text:
package com.matthewtamlin.spyglass.integrationtests.annotationcombinations.colorhandler;

import android.annotation.TargetApi;
import android.content.Context;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import com.matthewtamlin.spyglass.integrationtests.R;
import com.matthewtamlin.spyglass.integrationtests.framework.ReceivedValue;
import com.matthewtamlin.spyglass.markers.annotations.defaults.DefaultToInteger;
import com.matthewtamlin.spyglass.markers.annotations.unconditionalhandlers.ColorHandler;

public class WithDefaultToInteger extends ColorHandlerTestTargetBase {
  public static final int DEFAULT_VALUE = 142970;

  public WithDefaultToInteger(final Context context) {
    super(context);
    init(null, 0, 0);
  }

  public WithDefaultToInteger(final Context context, final AttributeSet attrs) {
    super(context, attrs);
    init(attrs, 0, 0);
  }

  public WithDefaultToInteger(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(attrs, defStyleAttr, 0);
  }

  @RequiresApi(21)
  @TargetApi(21)
  public WithDefaultToInteger(
      final Context context,
      final AttributeSet attrs,
      final int defStyleAttr,
      final int defStyleRes) {

    super(context, attrs, defStyleAttr, defStyleRes);
    init(attrs, defStyleAttr, defStyleRes);
  }

  @ColorHandler(attributeId = R.styleable.ColorHandlerTestTargetBase_colorHandlerAttr)
  @DefaultToInteger(DEFAULT_VALUE)
  public void handlerMethod(final int i) {
    setReceivedValue(ReceivedValue.of(i));
  }

  private void init(final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
    WithDefaultToInteger_SpyglassCompanion
        .builder()
        .setTarget(this)
        .setContext(getContext())
        .setStyleableResource(R.styleable.ColorHandlerTestTargetBase)
        .setAttributeSet(attrs)
        .setDefaultStyleAttribute(defStyleAttr)
        .setDefaultStyleResource(defStyleRes)
        .build()
        .callTargetMethodsNow();
  }
}


text:
"""

Module that manage the authentication service, both custom and social-based

"""


text:
using System;

namespace Ghul.Operations
{
	/// <summary>
	/// An arbitrary one-time action operation that takes no time.
	/// </summary>
	public class ActionOperation : Operation
	{
		/// <summary>
		/// The action of this operation.
		/// </summary>
		private Action action;

		/// <summary>
		/// Creates a new arbitrary one-time action operation that takes no time.
		/// </summary>
		/// <param name="action">The action of this operation.</param>
		/// <exception cref="ArgumentNullException">If action is null.</exception>
		public ActionOperation(Action action)
		{
			Ensure.IsNotNull(action, nameof(action));

			this.action = action;
		}

		/// <summary>
		/// Processes the operation based on the elapsed time.
		/// </summary>
		/// <param name="elapsedTime">The elapsed time.</param>
		/// <returns>The remaining time unused by the processing, must not be negative.</returns>
		/// <exception cref="ArgumentOutOfRangeException">If elapsedTime is negative.</exception>
		public override TimeSpan Process(TimeSpan elapsedTime)
		{
			Ensure.IsNotLessThan(elapsedTime, TimeSpan.Zero, nameof(elapsedTime));

			// Do nothing if already completed
			if(!HasCompleted)
			{
				action();

				HasCompleted = true;
			}

			// Does not take any time
			return elapsedTime;
		}
	}
}


text:
#include <aws/config/model/DescribeDeliveryChannelStatusResult.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/AmazonWebServiceResult.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/UnreferencedParam.h>

#include <utility>

using namespace Aws::ConfigService::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
using namespace Aws;

DescribeDeliveryChannelStatusResult::DescribeDeliveryChannelStatusResult()
{
}

DescribeDeliveryChannelStatusResult::DescribeDeliveryChannelStatusResult(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  *this = result;
}

DescribeDeliveryChannelStatusResult& DescribeDeliveryChannelStatusResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  JsonView jsonValue = result.GetPayload().View();
  if(jsonValue.ValueExists("DeliveryChannelsStatus"))
  {
    Array<JsonView> deliveryChannelsStatusJsonList = jsonValue.GetArray("DeliveryChannelsStatus");
    for(unsigned deliveryChannelsStatusIndex = 0; deliveryChannelsStatusIndex < deliveryChannelsStatusJsonList.GetLength(); ++deliveryChannelsStatusIndex)
    {
      m_deliveryChannelsStatus.push_back(deliveryChannelsStatusJsonList[deliveryChannelsStatusIndex].AsObject());
    }
  }

  return *this;
}


text:
echo "##################### EXECUTE: kurento_ci_container_dnat #####################"

############################################
# Craete container
container=$1
action=$2
docker_pid=$3
[ -n $4 ] && transport=$4
[ -n $5 ] && ip=$5

echo "Performing $action on container ID $container (pid=$docker_pid) with transport $transport"

if [ $action = 'start' ]; then

echo "Starting..."

echo "Selected ip: $ip"

# Add Net namespaces
[ ! -f /proc/$docker_pid/ns/net ] && echo "No such file /proc/$docker_pid/ns/net"
ln -s /proc/$docker_pid/ns/net /var/run/netns/$docker_pid-cont || (echo "No link created"; exit 1)
ls -la /var/run/netns/
ip netns list
ip netns add $docker_pid-bridge
ip netns add $docker_pid-route

# Create bridge & interfaces
ip netns exec $docker_pid-bridge brctl addbr br0
ip link add vethci$docker_pid type veth peer name vethce$docker_pid
ip link add vethrbi$docker_pid type veth peer name vethrbe$docker_pid
ip link add vethrai$docker_pid type veth peer name vethrae$docker_pid

# Assign interfaces to Net namespaces
ip link set vethci$docker_pid netns $docker_pid-cont
ip link set vethce$docker_pid netns $docker_pid-bridge
ip link set vethrbi$docker_pid netns $docker_pid-route
ip link set vethrbe$docker_pid netns $docker_pid-bridge
ip link set vethrai$docker_pid netns $docker_pid-route

# Link interfaces to bridges
brctl addif docker0 vethrae$docker_pid
ip netns exec $docker_pid-bridge brctl addif br0 vethce$docker_pid
ip netns exec $docker_pid-bridge brctl addif br0 vethrbe$docker_pid

# Configure IP addresses

# Container Internal
ip netns exec $docker_pid-cont ip link set dev vethci$docker_pid name eth0
ip netns exec $docker_pid-cont ip link set eth0 up
ip netns exec $docker_pid-cont ip addr add 192.168.0.100/24 dev eth0
ip netns exec $docker_pid-cont ip route add default via 192.168.0.1

# Container external (peer)
ip netns exec $docker_pid-bridge ip link set vethce$docker_pid up

# Bridge
ip netns exec $docker_pid-bridge ip link set br0 up
ip netns exec $docker_pid-bridge ip addr add 192.168.0.254/24 dev br0

# Router bridge internal
ip netns exec $docker_pid-route ip link set vethrbi$docker_pid up
ip netns exec $docker_pid-route ip addr add 192.168.0.1/24 dev vethrbi$docker_pid

# Router bridge external (peer)
ip netns exec $docker_pid-bridge ip link set vethrbe$docker_pid up

# Agent internal
ip netns exec $docker_pid-route ip link set vethrai$docker_pid up
ip netns exec $docker_pid-route ip addr add ${ip}/16 dev vethrai$docker_pid
ip netns exec $docker_pid-route ip route add default via 172.17.0.1

# Agent external
ip link set vethrae$docker_pid up

# Add SNAT
ip netns exec $docker_pid-route iptables -t nat -A POSTROUTING -o vethrai$docker_pid -j SNAT --to $ip
ip netns exec $docker_pid-route iptables -t nat -A PREROUTING -i vethrai$docker_pid -j DNAT --to 192.168.0.100
if [ $transport = 'TCP' ]; then
  # Allow UDP on port 3478 (for TURN)
  ip netns exec $docker_pid-route iptables -I FORWARD 1 -p udp --dport 3478 -s 192.168.0.0/24 -j ACCEPT
  ip netns exec $docker_pid-route iptables -A FORWARD -p udp --sport 3478 -j ACCEPT

  # Allow DNS
  ip netns exec $docker_pid-route iptables -A FORWARD -p udp --dport 53 -j ACCEPT
  ip netns exec $docker_pid-route iptables -A FORWARD -p udp --sport 53 -j ACCEPT

  ip netns exec $docker_pid-route iptables -A FORWARD -p udp -s 192.168.0.0/24 -j DROP

  # This is used to force RLFX TCP
#  ip netns exec $docker_pid-route iptables -I INPUT 1 -p udp -s 172.17.0.0/16 -j DROP
#  ip netns exec $docker_pid-route iptables -I FORWARD 1 -p udp -s 193.147.0.0/16 --sport 3478 -j ACCEPT
  ip netns exec $docker_pid-route iptables -A FORWARD -p udp -s 172.17.0.0/16 -j DROP

  # This is used to force RELAY
#  ip netns exec $docker_pid-route iptables -I INPUT 1 -p udp -s 172.16.0.0/16 -j DROP
#  ip netns exec $docker_pid-route iptables -I FORWARD 1 -p udp -s 172.16.0.0/16 -j DROP
  ip netns exec $docker_pid-route iptables -A FORWARD -p udp -s 193.147.0.0/16 -j DROP
fi

fi

if [ $action = 'destroy' ]; then

  ######################################################
  # Delete container
  echo "Destroying netns & interfaces related to $docker_pid..."

  ip netns exec $docker_pid-cont ip link del vethci$docker_pid
  ip netns exec $docker_pid-bridge ip link del vethce$docker_pid
  ip netns exec $docker_pid-bridge ip link del vethrbe$docker_pid
  ip netns exec $docker_pid-route ip link del vethrbi$docker_pid
  ip netns exec $docker_pid-route ip link del vethrai$docker_pid
  ip link del vethrae$docker_pid
  ip netns del $docker_pid-cont
  ip netns del $docker_pid-route
  ip netns del $docker_pid-bridge

fi


text:
<?php

namespace App\Models\Access\Role\Traits\Attribute;

/**
 * Class RoleAttribute
 * @package App\Models\Access\Role\Traits\Attribute
 */
trait RoleAttribute
{
    /**
     * @return string
     */
    public function getEditButtonAttribute()
    {
        if (access()->allow('edit-roles')) {
            return 'id) . '" class="btn btn-xs btn-primary"> ';
        }

        return '';
    }

    /**
     * @return string
     */
    public function getDeleteButtonAttribute()
    {
        //Can't delete master admin role
        if ($this->id != 1) {
            if (access()->allow('delete-roles')) {
                return 'id) . '" class="btn btn-xs btn-danger" data-method="delete">';
            }
        }

        return '';
    }

    /**
     * @return string
     */
    public function getActionButtonsAttribute()
    {
        return $this->getEditButtonAttribute() .
        $this->getDeleteButtonAttribute();
    }
}


text:
import time
import plyvel
import binascii

from logzero import logger

from neo.Core.Blockchain import Blockchain
from neo.Core.Header import Header
from neo.Core.Block import Block
from neo.Core.TX.Transaction import Transaction, TransactionType
from neocore.IO.BinaryWriter import BinaryWriter
from neocore.IO.BinaryReader import BinaryReader
from neo.IO.MemoryStream import StreamManager
from neo.Implementations.Blockchains.LevelDB.DBCollection import DBCollection
from neo.Implementations.Blockchains.LevelDB.CachedScriptTable import CachedScriptTable
from neocore.Fixed8 import Fixed8
from neocore.UInt160 import UInt160
from neocore.UInt256 import UInt256

from neo.Core.State.UnspentCoinState import UnspentCoinState
from neo.Core.State.AccountState import AccountState
from neo.Core.State.CoinState import CoinState
from neo.Core.State.SpentCoinState import SpentCoinState, SpentCoinItem, SpentCoin
from neo.Core.State.AssetState import AssetState
from neo.Core.State.ValidatorState import ValidatorState
from neo.Core.State.ContractState import ContractState
from neo.Core.State.StorageItem import StorageItem
from neo.Implementations.Blockchains.LevelDB.DBPrefix import DBPrefix

from neo.SmartContract.StateMachine import StateMachine
from neo.SmartContract.ApplicationEngine import ApplicationEngine
from neo.SmartContract import TriggerType
from neocore.Cryptography.Crypto import Crypto
from neocore.BigInteger import BigInteger
from neo.EventHub import events

class LevelDBBlockchain(Blockchain):
    _path = None
    _db = None

    _header_index = []
    _block_cache = {}

    _current_block_height = 0
    _stored_header_count = 0

    _disposed = False

    _verify_blocks = False

    # this is the version of the database
    # should not be updated for network version changes
    _sysversion = b'/NEO:2.0.1/'

    _persisting_block = None

    @property
    def CurrentBlockHash(self):
        try:
            return self._header_index[self._current_block_height]
        except Exception as e:
            logger.info("Could not get current block hash, returning none: %s ", )

        return None

    @property
    def CurrentBlockHashPlusOne(self):
        try:
            return self._header_index[self._current_block_height + 1]
        except Exception as e:
            pass
        return self.CurrentBlockHash

    @property
    def CurrentHeaderHash(self):
        return self._header_index[len(self._header_index) - 1]

    @property
    def HeaderHeight(self):
        height = len(self._header_index) - 1
        return height

    @property
    def Height(self):
        return self._current_block_height

    @property
    def CurrentBlock(self):
        if self._persisting_block:
            return self._persisting_block
        return self.GetBlockByHeight(self.Height)

    @property
    def Path(self):
        return self._path

    def __init__(self, path):
        super(LevelDBBlockchain, self).__init__()
        self._path = path

        self._header_index = []
        self._header_index.append(Blockchain.GenesisBlock().Header.Hash.ToBytes())

        try:
            self._db = plyvel.DB(self._path, create_if_missing=True)
        #            self._db = plyvel.DB(self._path, create_if_missing=True, bloom_filter_bits=16, compression=None)
        except Exception as e:
            logger.info("leveldb unavailable, you may already be running this process: %s " % e)
            raise Exception('Leveldb Unavailable')

        version = self._db.get(DBPrefix.SYS_Version)

        if version == self._sysversion:  # or in the future, if version doesn't equal the current version...

            ba = bytearray(self._db.get(DBPrefix.SYS_CurrentBlock, 0))
            self._current_block_height = int.from_bytes(ba[-4:], 'little')

            ba = bytearray(self._db.get(DBPrefix.SYS_CurrentHeader, 0))
            current_header_height = int.from_bytes(ba[-4:], 'little')
            current_header_hash = bytes(ba[:64].decode('utf-8'), encoding='utf-8')

            #            logger.info("current header hash!! %s " % current_header_hash)
            #            logger.info("current header height, hashes %s %s %s" %(self._current_block_height, self._header_index, current_header_height) )

            hashes = []
            try:
                for key, value in self._db.iterator(prefix=DBPrefix.IX_HeaderHashList):
                    ms = StreamManager.GetStream(value)
                    reader = BinaryReader(ms)
                    hlist = reader.Read2000256List()
                    key = int.from_bytes(key[-4:], 'little')
                    hashes.append({'k': key, 'v': hlist})
                    StreamManager.ReleaseStream(ms)
            #                hashes.append({'index':int.from_bytes(key, 'little'), 'hash':value})

            except Exception as e:
                logger.info("Could not get stored header hash list: %s " % e)

            if len(hashes):
                hashes.sort(key=lambda x: x['k'])
                genstr = Blockchain.GenesisBlock().Hash.ToBytes()
                for hlist in hashes:

                    for hash in hlist['v']:
                        if hash != genstr:
                            self._header_index.append(hash)
                        self._stored_header_count += 1

            if self._stored_header_count == 0:
                headers = []
                for key, value in self._db.iterator(prefix=DBPrefix.DATA_Block):
                    dbhash = bytearray(value)[8:]
                    headers.append(Header.FromTrimmedData(binascii.unhexlify(dbhash), 0))

                headers.sort(key=lambda h: h.Index)
                for h in headers:
                    if h.Index > 0:
                        self._header_index.append(h.Hash.ToBytes())

            elif current_header_height > self._stored_header_count:

                try:
                    hash = current_header_hash
                    targethash = self._header_index[-1]

                    newhashes = []
                    while hash != targethash:
                        header = self.GetHeader(hash)
                        newhashes.insert(0, header)
                        hash = header.PrevHash.ToBytes()

                    self.AddHeaders(newhashes)
                except Exception as e:
                    pass
        else:
            with self._db.write_batch() as wb:
                for key, value in self._db.iterator():
                    wb.delete(key)

            self.Persist(Blockchain.GenesisBlock())
            self._db.put(DBPrefix.SYS_Version, self._sysversion)

    def GetAccountState(self, script_hash, print_all_accounts=False):

        if type(script_hash) is str:
            try:
                script_hash = script_hash.encode('utf-8')
            except Exception as e:
                logger.info("could not convert argument to bytes :%s " % e)
                return None

        sn = self._db.snapshot()
        accounts = DBCollection(self._db, sn, DBPrefix.ST_Account, AccountState)
        acct = accounts.TryGet(keyval=script_hash)

        sn.close()

        return acct

    def GetStorageItem(self, storage_key):
        sn = self._db.snapshot()
        storages = DBCollection(self._db, sn, DBPrefix.ST_Storage, StorageItem)
        item = storages.TryGet(storage_key.GetHashCodeBytes())
        sn.close()
        return item

    def SearchContracts(self, query):
        res = []
        sn = self._db.snapshot()
        contracts = DBCollection(self._db, sn, DBPrefix.ST_Contract, ContractState)
        keys = contracts.Keys

        query = query.casefold()

        for item in keys:

            contract = contracts.TryGet(keyval=item)
            try:
                if query in contract.Name.decode('utf-8').casefold():
                    res.append(contract)
                elif query in contract.Author.decode('utf-8').casefold():
                    res.append(contract)
                elif query in contract.Description.decode('utf-8').casefold():
                    res.append(contract)
                elif query in contract.Email.decode('utf-8').casefold():
                    res.append(contract)
            except Exception as e:
                logger.info("Could not query contract: %s " % e)

        sn.close()

        return res

    def ShowAllContracts(self):

        sn = self._db.snapshot()
        contracts = DBCollection(self._db, sn, DBPrefix.ST_Contract, ContractState)
        keys = contracts.Keys
        sn.close()
        return keys

    def GetContract(self, hash):

        if type(hash) is str:
            try:
                hash = hash.encode('utf-8')
            except Exception as e:
                logger.info("could not convert argument to bytes :%s " % e)
                return None

        sn = self._db.snapshot()
        contracts = DBCollection(self._db, sn, DBPrefix.ST_Contract, ContractState)
        contract = contracts.TryGet(keyval=hash)
        sn.close()
        return contract

    def GetAllSpentCoins(self):
        sn = self._db.snapshot()
        coins = DBCollection(self._db, sn, DBPrefix.ST_SpentCoin, SpentCoinState)

        return coins.Keys

    def GetUnspent(self, hash, index):

        sn = self._db.snapshot()
        coins = DBCollection(self._db, sn, DBPrefix.ST_Coin, UnspentCoinState)

        state = coins.TryGet(hash)

        if state is None:
            return None
        if index >= len(state.Items):
            return None
        if state.Items[index] & CoinState.Spent > 0:
            return None
        tx, height = self.GetTransaction(hash)

        return tx.outputs[index]

    def GetSpentCoins(self, tx_hash):

        if type(tx_hash) is not bytes:
            tx_hash = bytes(tx_hash.encode('utf-8'))

        sn = self._db.snapshot()
        coins = DBCollection(self._db, sn, DBPrefix.ST_SpentCoin, SpentCoinState)

        result = coins.TryGet(keyval=tx_hash)

        sn.close()

        return result

    def GetAllUnspent(self, hash):

        unspents = []

        sn = self._db.snapshot()
        unspentcoins = DBCollection(self._db, sn, DBPrefix.ST_Coin, UnspentCoinState)

        state = unspentcoins.TryGet(keyval=hash.ToBytes())

        if state:
            tx, height = self.GetTransaction(hash)

            for index, item in enumerate(state.Items):
                if item & CoinState.Spent == 0:
                    unspents.append(tx.outputs[index])
        else:
            print("no state?")
        return unspents

    def GetUnclaimed(self, hash):

        tx, height = self.GetTransaction(hash)

        if tx is None:
            return None

        out = {}
        sn = self._db.snapshot()
        coins = DBCollection(self._db, sn, DBPrefix.ST_SpentCoin, SpentCoinState)

        state = coins.TryGet(keyval=hash.ToBytes())

        if state:
            for item in state.Items:
                out[item.index] = SpentCoin(tx.outputs[item.index], height, item.height)

        sn.close()

        return out

    def SearchAssetState(self, query):
        res = []
        sn = self._db.snapshot()
        assets = DBCollection(self._db, sn, DBPrefix.ST_Asset, AssetState)
        keys = assets.Keys

        for item in keys:
            asset = assets.TryGet(keyval=item)
            if query in asset.Name.decode('utf-8'):
                res.append(asset)
            elif query in Crypto.ToAddress(asset.Issuer):
                res.append(asset)
            elif query in Crypto.ToAddress(asset.Admin):
                res.append(asset)
        sn.close()

        return res

    def GetAssetState(self, assetId):

        if type(assetId) is str:
            try:
                assetId = assetId.encode('utf-8')
            except Exception as e:
                logger.info("could not convert argument to bytes :%s " % e)
                return None

        sn = self._db.snapshot()
        assets = DBCollection(self._db, sn, DBPrefix.ST_Asset, AssetState)
        asset = assets.TryGet(assetId)

        return asset

    def GetTransaction(self, hash):

        if type(hash) is str:
            hash = hash.encode('utf-8')
        elif type(hash) is UInt256:
            hash = hash.ToBytes()

        out = self._db.get(DBPrefix.DATA_Transaction + hash)
        if out is not None:
            out = bytearray(out)
            height = int.from_bytes(out[:4], 'little')
            out = out[4:]
            outhex = binascii.unhexlify(out)
            return Transaction.DeserializeFromBufer(outhex, 0), height

        logger.info("Could not find transaction for hash %s " % hash)
        return None, -1

    def AddBlock(self, block):

        if not block.Hash.ToBytes() in self._block_cache:
            self._block_cache[block.Hash.ToBytes()] = block

        header_len = len(self._header_index)

        if block.Index - 1 >= header_len:
            return False

        if block.Index == header_len:

            if self._verify_blocks and not block.Verify():
                return False

            self.AddHeader(block.Header)

        return True

    def ContainsBlock(self, index):
        if index <= self._current_block_height:
            return True
        return False

    def ContainsTransaction(self, hash):
        tx = self._db.get(DBPrefix.DATA_Transaction + hash.ToBytes())
        return True if tx is not None else False

    def GetHeader(self, hash):

        try:
            out = bytearray(self._db.get(DBPrefix.DATA_Block + hash))
            out = out[8:]
            outhex = binascii.unhexlify(out)
            return Header.FromTrimmedData(outhex, 0)
        except TypeError as e2:
            pass
        except Exception as e:
            logger.info("OTHER ERRROR %s " % e)
        return None

    def GetHeaderBy(self, height_or_hash):
        hash = None

        intval = None
        try:
            intval = int(height_or_hash)
        except Exception as e:
            pass

        if not type(height_or_hash) == BigInteger and len(height_or_hash) == 64:
            bhash = height_or_hash.encode('utf-8')
            if bhash in self._header_index:
                hash = bhash

        elif intval is not None and self.GetHeaderHash(intval) is not None:
            hash = self.GetHeaderHash(int(height_or_hash))

        if hash is not None:
            return self.GetHeader(hash)

        return None

    def GetHeaderByHeight(self, height):

        if len(self._header_index) <= height:
            return False

        hash = self._header_index[height]

        return self.GetHeader(hash)

    def GetHeaderHash(self, height):
        if height < len(self._header_index) and height >= 0:
            return self._header_index[height]
        return None

    def GetBlockHash(self, height):
        """
        Get the block hash by its block height
        Args:
            height(int): height of the block to retrieve hash from.

        Returns:
            bytes: a non-raw block hash (i.e. b'6dd83ed8a3fc02e322f91f30431bf3662a8c8e8ebe976c3565f0d21c70620991', but not b'\x6d\xd8...etc'
        """
        if self._current_block_height < height:
            return

        if len(self._header_index) <= height:
            return

        return self._header_index[height]

    def GetSysFeeAmount(self, hash):

        if type(hash) is UInt256:
            hash = hash.ToBytes()
        try:
            value = self._db.get(DBPrefix.DATA_Block + hash)[0:8]
            amount = int.from_bytes(value, 'little', signed=False)
            return amount
        except Exception as e:
            logger.info("Could not get sys fee: %s " % e)

        return 0

    def GetBlockByHeight(self, height):
        """
        Get a block by its height.
        Args:
            height(int): the height of the block to retrieve.

        Returns:
            neo.Core.Block: block instance.
        """
        hash = self.GetBlockHash(height)
        if hash is not None:
            return self.GetBlockByHash(hash)

    def GetBlock(self, height_or_hash):

        hash = None

        intval = None
        try:
            intval = int(height_or_hash)
        except Exception as e:
            pass

        if intval is None and len(height_or_hash) == 64:
            bhash = height_or_hash.encode('utf-8')
            if bhash in self._header_index:
                hash = bhash
        elif intval is None and len(height_or_hash) == 66:
            bhash = height_or_hash[2:].encode('utf-8')
            if bhash in self._header_index:
                hash = bhash
        elif intval is not None and self.GetBlockHash(intval) is not None:
            hash = self.GetBlockHash(intval)

        if hash is not None:
            return self.GetBlockByHash(hash)

        return None

    def GetBlockByHash(self, hash):
        try:
            out = bytearray(self._db.get(DBPrefix.DATA_Block + hash))
            out = out[8:]
            outhex = binascii.unhexlify(out)
            return Block.FromTrimmedData(outhex, 0)
        except Exception as e:
            logger.info("Could not get block %s " % e)
        return None

    def GetNextBlockHash(self, hash):
        header = self.GetHeader(hash.ToBytes())
        if header:
            if header.Index + 1 >= len(self._header_index):
                return None
            return self._header_index[header.Index + 1]
        return None

    def AddHeader(self, header):
        self.AddHeaders([header])

    def AddHeaders(self, headers):

        newheaders = []
        count = 0
        for header in headers:

            if header.Index - 1 >= len(self._header_index) + count:
                logger.info(
                    "header is greater than header index length: %s %s " % (header.Index, len(self._header_index)))
                break

            if header.Index < count + len(self._header_index):
                continue
            if self._verify_blocks and not header.Verify():
                break

            count = count + 1

            newheaders.append(header)

        if len(newheaders):
            self.ProcessNewHeaders(newheaders)

        return True

    def ProcessNewHeaders(self, headers):
        start = time.clock()

        lastheader = headers[-1]

        hashes = [h.Hash.ToBytes() for h in headers]

        self._header_index = self._header_index + hashes

        logger.debug("Process Headers: %s %s" % (lastheader, (time.clock() - start)))

        if lastheader is not None:
            self.OnAddHeader(lastheader)

    def OnAddHeader(self, header):

        hHash = header.Hash.ToBytes()

        if hHash not in self._header_index:
            self._header_index.append(hHash)

        while header.Index - 2000 >= self._stored_header_count:
            ms = StreamManager.GetStream()
            w = BinaryWriter(ms)
            headers_to_write = self._header_index[self._stored_header_count:self._stored_header_count + 2000]
            w.Write2000256List(headers_to_write)
            out = ms.ToArray()
            StreamManager.ReleaseStream(ms)
            with self._db.write_batch() as wb:
                wb.put(DBPrefix.IX_HeaderHashList + self._stored_header_count.to_bytes(4, 'little'), out)

            self._stored_header_count += 2000

            logger.debug("Trimming stored header index %s" % self._stored_header_count)

        with self._db.write_batch() as wb:
            wb.put(DBPrefix.DATA_Block + hHash, bytes(8) + header.ToArray())
            wb.put(DBPrefix.SYS_CurrentHeader, hHash + header.Index.to_bytes(4, 'little'))

    @property
    def BlockCacheCount(self):
        return len(self._block_cache)

    def Persist(self, block):

        self._persisting_block = block

        sn = self._db.snapshot()
        accounts = DBCollection(self._db, sn, DBPrefix.ST_Account, AccountState)
        unspentcoins = DBCollection(self._db, sn, DBPrefix.ST_Coin, UnspentCoinState)
        spentcoins = DBCollection(self._db, sn, DBPrefix.ST_SpentCoin, SpentCoinState)
        assets = DBCollection(self._db, sn, DBPrefix.ST_Asset, AssetState)
        validators = DBCollection(self._db, sn, DBPrefix.ST_Validator, ValidatorState)
        contracts = DBCollection(self._db, sn, DBPrefix.ST_Contract, ContractState)
        storages = DBCollection(self._db, sn, DBPrefix.ST_Storage, StorageItem)

        amount_sysfee = self.GetSysFeeAmount(block.PrevHash) + block.TotalFees().value
        amount_sysfee_bytes = amount_sysfee.to_bytes(8, 'little')

        to_dispatch = []

        with self._db.write_batch() as wb:

            wb.put(DBPrefix.DATA_Block + block.Hash.ToBytes(), amount_sysfee_bytes + block.Trim())

            for tx in block.Transactions:

                wb.put(DBPrefix.DATA_Transaction + tx.Hash.ToBytes(), block.IndexBytes() + tx.ToArray())

                # go through all outputs and add unspent coins to them

                unspentcoinstate = UnspentCoinState.FromTXOutputsConfirmed(tx.outputs)
                unspentcoins.Add(tx.Hash.ToBytes(), unspentcoinstate)

                # go through all the accounts in the tx outputs
                for output in tx.outputs:
                    account = accounts.GetAndChange(output.AddressBytes, AccountState(output.ScriptHash))

                    if account.HasBalance(output.AssetId):
                        account.AddToBalance(output.AssetId, output.Value)
                    else:
                        account.SetBalanceFor(output.AssetId, output.Value)

                # go through all tx inputs
                unique_tx_input_hashes = []
                for input in tx.inputs:
                    if input.PrevHash not in unique_tx_input_hashes:
                        unique_tx_input_hashes.append(input.PrevHash)

                for txhash in unique_tx_input_hashes:
                    prevTx, height = self.GetTransaction(txhash.ToBytes())
                    coin_refs_by_hash = [coinref for coinref in tx.inputs if
                                         coinref.PrevHash.ToBytes() == txhash.ToBytes()]
                    for input in coin_refs_by_hash:

                        uns = unspentcoins.GetAndChange(input.PrevHash.ToBytes())
                        uns.OrEqValueForItemAt(input.PrevIndex, CoinState.Spent)

                        if prevTx.outputs[input.PrevIndex].AssetId.ToBytes() == Blockchain.SystemShare().Hash.ToBytes():
                            sc = spentcoins.GetAndChange(input.PrevHash.ToBytes(),
                                                         SpentCoinState(input.PrevHash, height, []))
                            sc.Items.append(SpentCoinItem(input.PrevIndex, block.Index))

                        output = prevTx.outputs[input.PrevIndex]
                        acct = accounts.GetAndChange(prevTx.outputs[input.PrevIndex].AddressBytes,
                                                     AccountState(output.ScriptHash))
                        assetid = prevTx.outputs[input.PrevIndex].AssetId
                        acct.SubtractFromBalance(assetid, prevTx.outputs[input.PrevIndex].Value)

                # do a whole lotta stuff with tx here...
                if tx.Type == TransactionType.RegisterTransaction:
                    asset = AssetState(tx.Hash, tx.AssetType, tx.Name, tx.Amount,
                                       Fixed8(0), tx.Precision, Fixed8(0), Fixed8(0), UInt160(data=bytearray(20)),
                                       tx.Owner, tx.Admin, tx.Admin, block.Index + 2 * 2000000, False)

                    assets.Add(tx.Hash.ToBytes(), asset)

                elif tx.Type == TransactionType.IssueTransaction:

                    txresults = [result for result in tx.GetTransactionResults() if result.Amount.value < 0]
                    for result in txresults:
                        asset = assets.GetAndChange(result.AssetId.ToBytes())
                        asset.Available = asset.Available - result.Amount

                elif tx.Type == TransactionType.ClaimTransaction:
                    for input in tx.Claims:

                        sc = spentcoins.TryGet(input.PrevHash.ToBytes())
                        if sc and sc.HasIndex(input.PrevIndex):
                            sc.DeleteIndex(input.PrevIndex)
                            spentcoins.GetAndChange(input.PrevHash.ToBytes())

                elif tx.Type == TransactionType.EnrollmentTransaction:
                    newvalidator = ValidatorState(pub_key=tx.PublicKey)
                    validators.GetAndChange(tx.PublicKey.ToBytes(), newvalidator)
                elif tx.Type == TransactionType.StateTransaction:
                    # @TODO Implement persistence for State Descriptors
                    pass

                elif tx.Type == TransactionType.PublishTransaction:
                    contract = ContractState(tx.Code, tx.NeedStorage, tx.Name, tx.CodeVersion,
                                             tx.Author, tx.Email, tx.Description)

                    contracts.GetAndChange(tx.Code.ScriptHash().ToBytes(), contract)
                elif tx.Type == TransactionType.InvocationTransaction:

                    script_table = CachedScriptTable(contracts)
                    service = StateMachine(accounts, validators, assets, contracts, storages, wb)

                    engine = ApplicationEngine(
                        trigger_type=TriggerType.Application,
                        container=tx,
                        table=script_table,
                        service=service,
                        gas=tx.Gas,
                        testMode=False
                    )

                    engine.LoadScript(tx.Script, False)

                    try:
                        success = engine.Execute()
                        service.ExecutionCompleted(engine, success)

                    except Exception as e:
                        service.ExecutionCompleted(engine, False, e)

                    to_dispatch = to_dispatch + service.events_to_dispatch
                else:

                    if tx.Type != b'\x00' and tx.Type != 128:
                        logger.info("TX Not Found %s " % tx.Type)

            # do save all the accounts, unspent, coins, validators, assets, etc
            # now sawe the current sys block

            # filter out accounts to delete then commit
            for key, account in accounts.Current.items():
                if not account.IsFrozen and len(account.Votes) == 0 and account.AllBalancesZeroOrLess():
                    accounts.Remove(key)

            accounts.Commit(wb)

            # filte out unspent coins to delete then commit
            for key, unspent in unspentcoins.Current.items():
                if unspent.IsAllSpent:
                    unspentcoins.Remove(key)
            unspentcoins.Commit(wb)

            # filter out spent coins to delete then commit to db
            for key, spent in spentcoins.Current.items():
                if len(spent.Items) == 0:
                    spentcoins.Remove(key)
            spentcoins.Commit(wb)

            # commit validators
            validators.Commit(wb)

            # commit assets
            assets.Commit(wb)

            # commit contracts
            contracts.Commit(wb)

            # commit storages ( not implemented )
            storages.Commit(wb)

            sn.close()

            wb.put(DBPrefix.SYS_CurrentBlock, block.Hash.ToBytes() + block.IndexBytes())
            self._current_block_height = block.Index
            self._persisting_block = None

            for event in to_dispatch:
                events.emit(event.event_type, event)

    def PersistBlocks(self):
        #        logger.info("PERRRRRSISST:: Hheight, b height, cache: %s/%s %s  --%s %s" % (self.Height, self.HeaderHeight, len(self._block_cache), self.CurrentHeaderHash, self.BlockSearchTries))

        while not self._disposed:

            if len(self._header_index) <= self._current_block_height + 1:
                break

            hash = self._header_index[self._current_block_height + 1]

            if hash not in self._block_cache:
                self.BlockSearchTries += 1
                break

            self.BlockSearchTries = 0
            block = self._block_cache[hash]

            try:
                self.Persist(block)
                self.OnPersistCompleted(block)
                del self._block_cache[hash]
            except Exception as e:
                logger.info("Could not persist block %s " % e)
                raise e

    def Dispose(self):
        self._db.close()
        self._disposed = True


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2017 Capital One Services, LLC and Bitwise, Inc.
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License
 -->

<p:graph name="InputFileHiveParquetTimeStampSimple" xmlns:p="hydrograph/engine/jaxb/main"
         xmlns:it="hydrograph/engine/jaxb/inputtypes" xmlns:ot="hydrograph/engine/jaxb/outputtypes"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="hydrograph/engine/jaxb/main ../../../hydrograph.engine.core/src/main/resources/newxmlschema/main/main.xsd ">

    <inputs id="hive_parquet" batch="0" xsi:type="it:parquetHiveFile">
		<outSocket id="out0">
			<schema name="schema1">
				<field name="f4" type="java.util.Date" format="yyyy-MM-dd HH:mm:ss" />
			</schema>
		</outSocket>
		<databaseName value="@{databaseName}" />
		<tableName value="@{tableName}" />
	</inputs>

     <outputs id="OFDelimited_01" batch="0" xsi:type="ot:textFileDelimited">
        <inSocket fromComponentId="hive_parquet" fromSocketId="out0" id="in0" type="in" >
            <schema name="schema2">
              <field name="f4" type="java.util.Date" format="yyyy-MM-dd HH:mm:ss" />
            </schema>
        </inSocket>
        <path uri="testData/Output/HiveParquetTimeStampSimple"/>
        <delimiter value="|"/>
        <hasHeader value="false"/>
        <safe value="false"/>
        <strict value="true"/>
        <charset value="UTF-8"/>
    </outputs>

 </p:graph>


text:
//
//
//                            PayOff2.h
//
//

#ifndef PAYOFF2_H
#define PAYOFF2_H

class PayOff
{
public:

    PayOff(){};
    virtual double operator()(double Spot) const=0;
    virtual ~PayOff(){}

private:

};

class PayOffCall : public PayOff
{
public:

    PayOffCall(double Strike_);
    virtual double operator()(double Spot) const;
    virtual ~PayOffCall(){}

private:

    double Strike;

};

class PayOffPut : public PayOff
{
public:

    PayOffPut(double Strike_);
    virtual double operator()(double Spot) const;
    virtual ~PayOffPut(){}

private:

    double Strike;

};

#endif


text:
using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;

using FlagsAndCommand = MatterHackers.Agg.ShapePath.FlagsAndCommand;

namespace MatterHackers.Agg.VertexSource
{
	//=====================================================================arc
	//
	// See Implementation agg_arc.cpp
	//
	public class Arc : VertexSourceLegacySupport
	{
		private Direction direction;

		private double endAngle;

		private double flattenedDeltaAngle;

		private Vector2 origin;

		private Vector2 radius;

		public double ResolutionScale { get; set; } = 1;

		private double startAngle;

		public Arc()
		{
		}

		public Arc(double originX, double originY,
			 double radiusX, double radiusY,
			 double startAngle, double endAngle,
			 Direction direction = Direction.CounterClockWise)
		{
			init(originX, originY, radiusX, radiusY, startAngle, endAngle, direction);
		}

		public Arc(Vector2 origin,
			 Vector2 radius,
			 double startAngle, double endAngle,
			 Direction direction = Direction.CounterClockWise)
		{
			init(origin, radius, startAngle, endAngle, direction);
		}

		public enum Direction
		{
			ClockWise,
			CounterClockWise,
		}

		public void init(double originX, double originY,
			double radiusX, double radiusY,
			double startAngle, double endAngle,
			Direction direction = Direction.CounterClockWise)
		{
			init(new Vector2(originX, originY), new Vector2(radiusX, radiusY), startAngle, endAngle, direction);
		}

		public void init(Vector2 origin,
			Vector2 radius,
			double startAngle, double endAngle,
			Direction direction = Direction.CounterClockWise)
		{
			this.origin = origin;
			this.radius = radius;
			this.startAngle = startAngle;
			this.endAngle = endAngle;
			this.direction = direction;
		}

		public override IEnumerable<VertexData> Vertices()
		{
			double averageRadius = (Math.Abs(radius.X) + Math.Abs(radius.Y)) / 2;
			flattenedDeltaAngle = Math.Acos(averageRadius / (averageRadius + 0.125 / ResolutionScale)) * 2;
			while (endAngle < startAngle)
			{
				endAngle += Math.PI * 2.0;
			}

			VertexData vertexData = new VertexData();
			vertexData.command = FlagsAndCommand.MoveTo;
			if (direction == Direction.CounterClockWise)
			{
				vertexData.position = new Vector2(origin.X + Math.Cos(startAngle) * radius.X, origin.Y + Math.Sin(startAngle) * radius.Y);
				yield return vertexData;

				vertexData.command = FlagsAndCommand.LineTo;
				double angle = startAngle;
				int numSteps = (int)((endAngle - startAngle) / flattenedDeltaAngle);

				for (int i = 0; i <= numSteps; i++)
				{
					if (angle < endAngle)
					{
						vertexData.position = new Vector2(origin.X + Math.Cos(angle) * radius.X, origin.Y + Math.Sin(angle) * radius.Y);
						yield return vertexData;

						angle += flattenedDeltaAngle;
					}
				}

				vertexData.position = new Vector2(origin.X + Math.Cos(endAngle) * radius.X, origin.Y + Math.Sin(endAngle) * radius.Y);
				yield return vertexData;
			}
			else
			{
				vertexData.position = new Vector2(origin.X + Math.Cos(endAngle) * radius.X, origin.Y + Math.Sin(endAngle) * radius.Y);
				yield return vertexData;

				vertexData.command = FlagsAndCommand.LineTo;
				double angle = endAngle;
				int numSteps = (int)((endAngle - startAngle) / flattenedDeltaAngle);
				for (int i = 0; i <= numSteps; i++)
				{
					vertexData.position = new Vector2(origin.X + Math.Cos(angle) * radius.X, origin.Y + Math.Sin(angle) * radius.Y);
					yield return vertexData;

					angle -= flattenedDeltaAngle;
				}

				vertexData.position = new Vector2(origin.X + Math.Cos(startAngle) * radius.X, origin.Y + Math.Sin(startAngle) * radius.Y);
				yield return vertexData;
			}

			vertexData.command = FlagsAndCommand.Stop;
			yield return vertexData;
		}
	}
}