text:
package com.rmi.util;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;

//此为远程对象调用的接口,必须继承Remote类
public interface PersonService extends Remote {
    public List<PersonEntity> getList() throws RemoteException;
}


text:
@interface CMMotionManager (Shared)

+ (CMMotionManager *)sharedMotionManager;

@end

redpajama_set_name: RedPajamaGithub


text:
// Adopted from
// https://github.com/ampproject/amp-toolbox/blob/0c8755016ae825b11b63b98be83271fd14cc0486/packages/optimizer/lib/transformers/AddBlurryImagePlaceholders.js

const { promisify } = require("util");
const sharp = require("sharp");
const sizeOf = promisify(require("image-size"));
const DatauriParser = require("datauri/parser");
const parser = new DatauriParser();
const readFile = promisify(require("fs").readFile);
const writeFile = promisify(require("fs").writeFile);
const exists = promisify(require("fs").exists);

const PIXEL_TARGET = 60;

const ESCAPE_TABLE = {
  "#": "%23",
  "%": "%25",
  ":": "%3A",
  "<": "%3C",
  ">": "%3E",
  '"': "'",
};
const ESCAPE_REGEX = new RegExp(Object.keys(ESCAPE_TABLE).join("|"), "g");
function escaper(match) {
  return ESCAPE_TABLE[match];
}

const cache = {};

async function getCachedDataURI(src) {
  if (cache[src]) {
    return cache[src];
  }
  return (cache[src] = getDataURI(src));
}

async function getDataURI(src) {
  const info = await sizeOf(src);
  const imgDimension = getBitmapDimensions_(info.width, info.height);
  const buffer = await sharp(src)
    .rotate() // Manifest rotation from metadata
    .resize(imgDimension.width, imgDimension.height)
    .png()
    .toBuffer();
  const result = {
    src: parser.format(".png", buffer).content,
    width: info.width,
    height: info.height,
  };
  return result;
}

function getBitmapDimensions_(imgWidth, imgHeight) {
  // Aims for a bitmap of ~P pixels (w * h = ~P).
  // Gets the ratio of the width to the height. (r = w0 / h0 = w / h)
  const ratioWH = imgWidth / imgHeight;
  // Express the width in terms of height by multiply the ratio by the
  // height. (h * r = (w / h) * h)
  // Plug this representation of the width into the original equation.
  // (h * r * h = ~P).
  // Divide the bitmap size by the ratio to get the all expressions using
  // height on one side. (h * h = ~P / r)
  let bitmapHeight = PIXEL_TARGET / ratioWH;
  // Take the square root of the height instances to find the singular value
  // for the height. (h = sqrt(~P / r))
  bitmapHeight = Math.sqrt(bitmapHeight);
  // Divide the goal total pixel amount by the height to get the width.
  // (w = ~P / h).
  const bitmapWidth = PIXEL_TARGET / bitmapHeight;
  return { width: Math.round(bitmapWidth), height: Math.round(bitmapHeight) };
}

module.exports = async function (src) {
  const filename = "_site/" + src;
  const cachedName = filename + ".blurred";
  if (await exists(cachedName)) {
    return readFile(cachedName, {
      encoding: "utf-8",
    });
  }
  // We wrap the blurred image in a SVG to avoid rasterizing the filter on each layout.
  const dataURI = await getCachedDataURI(filename);
  let svg = `<svg xmlns="http://www.w3.org/2000/svg"
                  xmlns:xlink="http://www.w3.org/1999/xlink"
                  viewBox="0 0 ${dataURI.width} ${dataURI.height}">
                  <filter id="b" color-interpolation-filters="sRGB">
                    <feGaussianBlur stdDeviation=".5"></feGaussianBlur>
                    <feComponentTransfer>
                      <feFuncA type="discrete" tableValues="1 1"></feFuncA>
                    </feComponentTransfer>
                  </filter>
                  <image filter="url(#b)" preserveAspectRatio="none"
                    height="100%" width="100%"
                    xlink:href="${dataURI.src}">
                  </image>
                </svg>`;

  // Optimizes dataURI length by deleting line breaks, and
  // removing unnecessary spaces.
  svg = svg.replace(/\s+/g, " ");
  svg = svg.replace(/> </g, "><");
  svg = svg.replace(ESCAPE_REGEX, escaper);

  console.log(src, "[SUCCESS]");
  const URI = `data:image/svg+xml;charset=utf-8,${svg}`;
  await writeFile(cachedName, URI);
  return URI;
};


text:
import unittest

from libsaas import http
from libsaas.filters import auth

class BasicAuthTestCase(unittest.TestCase):

    def test_simple(self):
        auth_filter = auth.BasicAuth('user', 'pass')
        req = http.Request('GET', 'http://example.net/')
        auth_filter(req)

        self.assertEqual(req.headers['Authorization'], 'Basic dXNlcjpwYXNz')

    def test_unicode(self):
        # try both a unicode and a bytes parameter
        _lambda = b'\xce\xbb'
        _ulambda = _lambda.decode('utf-8')

        auth_bytes = auth.BasicAuth('user', _lambda)
        auth_unicode = auth.BasicAuth('user', _ulambda)
        auth_mixed = auth.BasicAuth(_lambda, _ulambda)

        expected_bytes = 'Basic dXNlcjrOuw=='
        expected_unicode = expected_bytes
        expected_mixed = 'Basic zrs6zrs='

        for auth_filter, expected in ((auth_bytes, expected_bytes),
                                      (auth_unicode, expected_unicode),
                                      (auth_mixed, expected_mixed)):

            req = http.Request('GET', 'http://example.net/')
            auth_filter(req)

            self.assertEqual(req.headers['Authorization'], expected)


text:
echo "Updating packages"

sudo apt-get update
sudo apt-get install -y curl

echo "********************"
echo "Installing libraries"

sudo apt-get install -y build-essential python3-pip python3-dev python3-venv gfortran libatlas-base-dev libblas-dev liblapack-dev libssl-dev

echo "********************"
echo "Create user 'lerero'"

sudo adduser --system --group lerero

echo "******************************"
echo "Create regularroutes directory"

sudo mkdir -p /opt/regularroutes
# chef sets the owner, group and chmod for the directory, when running osm or default scripts.

echo "********************************************************************"
echo "Installing a chef-client (https://www.chef.io/download-chef-client/)"
echo "Sample location /opt/chef/ is assumed."

curl -L https://www.chef.io/chef/install.sh | sudo bash


text:
package org.kie.internal.runtime.manager.audit.query;

import org.kie.api.executor.STATUS;

public interface RequestInfoLogDeleteBuilder extends AuditDateDeleteBuilder<RequestInfoLogDeleteBuilder>{

    /**
     * Specify one or more deployment ids to use as a criteria.
     * @param deploymentId one or more string deployment ids
     * @return The current query builder instance
     */
    public RequestInfoLogDeleteBuilder deploymentId(String... deploymentId);

    /**
     * Specify one more statuses (in the form of an int) as criteria.
     * @param status one or more int statuses
     * @return The current instance of this query builder
     */
    public RequestInfoLogDeleteBuilder status(STATUS... status);

}


text:
package net.sourceforge.plantuml.code.deflate;

import java.io.ByteArrayOutputStream;

/*
 * Simple DEFLATE decompressor
 * Copyright (c) Project Nayuki
 *
 * https://www.nayuki.io/page/simple-deflate-decompressor
 * https://github.com/nayuki/Simple-DEFLATE-decompressor
 */

import java.io.Closeable;
import java.io.IOException;

public class OutputStreamProtected implements Closeable {

	public static final int MAX_OUTPUT_SIZE = 1 * 1024 * 1024;

	private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
	private int counter = 0;

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

	public byte[] toByteArray() {
		return baos.toByteArray();
	}

	public void write(int b) throws IOException {
		this.counter++;
		baos.write(b);
		if (counter > MAX_OUTPUT_SIZE) {
			throw new IOException("Too big");
		}

	}

}


text:
(function (app) {
    'use strict';

    app.controller('menuDetailsCtrl', menuDetailsCtrl);

    menuDetailsCtrl.$inject = ['$scope', '$location', '$routeParams', '$modal', 'apiService', 'notificationService'];

    function menuDetailsCtrl($scope, $location, $routeParams, $modal, apiService, notificationService) {
        $scope.pageClass = 'page-menu';
        $scope.movie = {};
        $scope.loadingMovie = true;
        $scope.loadingRentals = true;
        $scope.isReadOnly = true;
        $scope.openRentDialog = openRentDialog;
        $scope.returnMovie = returnMovie;
        $scope.rentalHistory = [];
        $scope.getStatusColor = getStatusColor;
        $scope.clearSearch = clearSearch;
        $scope.isBorrowed = isBorrowed;

        function loadMovie() {

            $scope.loadingMovie = true;

            apiService.get('/api/menu/details/' + $routeParams.id, null,
            movieLoadCompleted,
            movieLoadFailed);
        }

        function loadRentalHistory() {
            $scope.loadingRentals = true;

            apiService.get('/api/rentals/' + $routeParams.id + '/rentalhistory', null,
            rentalHistoryLoadCompleted,
            rentalHistoryLoadFailed);
        }

        function loadMovieDetails() {
            loadMovie();
            loadRentalHistory();
        }

        function returnMovie(rentalID) {
            apiService.post('/api/rentals/return/' + rentalID, null,
            returnMovieSucceeded,
            returnMovieFailed);
        }

        function isBorrowed(rental)
        {
            return rental.Status == 'Borrowed';
        }

        function getStatusColor(status) {
            if (status == 'Borrowed')
                return 'red'
            else {
                return 'green';
            }
        }

        function clearSearch()
        {
            $scope.filterRentals = '';
        }

        function movieLoadCompleted(result) {
            $scope.movie = result.data;
            $scope.loadingMovie = false;
        }

        function movieLoadFailed(response) {
            notificationService.displayError(response.data);
        }

        function rentalHistoryLoadCompleted(result) {
            console.log(result);
            $scope.rentalHistory = result.data;
            $scope.loadingRentals = false;
        }

        function rentalHistoryLoadFailed(response) {
            notificationService.displayError(response);
        }

        function returnMovieSucceeded(response) {
            notificationService.displaySuccess('Movie returned to HomeCinema succeesfully');
            loadMovieDetails();
        }

        function returnMovieFailed(response) {
            notificationService.displayError(response.data);
        }

        function openRentDialog() {
            $modal.open({
                templateUrl: 'scripts/app/rental/rentMovieModal.html',
                controller: 'rentMovieCtrl',
                scope: $scope
            }).result.then(function ($scope) {
                loadMovieDetails();
            }, function () {
            });
        }

        loadMovieDetails();
    }

})(angular.module('myRestaurant'));


text:
<!DOCTYPE html>

    <title>  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>

 Docs (0% documented)

         Reference

          Reference

IDZSwiftCommonCryptoCocoaPodsTest

A simple app project to test building and linking against IDZSwiftCommonCrypto using CocoaPods

© 2015 . All rights reserved. (Last updated: 2015-11-04)

Generated by jazzy ♪♫ v0.3.2, a Realm project.


text:
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Microsoft.CodeAnalysis.Sarif
{
    // This enum is used to identify specific runtime conditions
    // encountered during execution. This mechanism is used by
    // unit tests to ensure that failure conditions travel expected
    // code paths. These conditions are a combination of fatal
    // and non-fatal circumstances
    [Flags]
    public enum RuntimeConditions
    {
        None = 0,

        // Not used today but perhaps soon...
        //CouldNotLoadCustomLoggerAssembly,
        //CouldNotLoadCustomLoggerType,
        //UnrecognizedDefaultLoggerExtension,
        //MalformedCustomLoggersArgument,
        //LoggerFailedInitialization,
        //LoggerRaisedExceptionOnInitialization,
        //LoggerRaisedExceptionOnWrite,
        //LoggerRaisedExceptionOnClose,

        // Fatal conditions
        ExceptionInstantiatingSkimmers = 0x01,
        ExceptionInSkimmerInitialize = 0x02,
        ExceptionRaisedInSkimmerCanAnalyze = 0x04,
        ExceptionInSkimmerAnalyze = 0x08,
        ExceptionCreatingLogFile = 0x10,
        ExceptionLoadingPdb = 0x20,
        ExceptionInEngine = 0x40,
        ExceptionLoadingTargetFile = 0x80,
        ExceptionLoadingAnalysisPlugin = 0x100,
        NoRulesLoaded = 0x200,
        NoValidAnalysisTargets = 0x400,
        RuleMissingRequiredConfiguration = 0x800,
        TargetParseError = 0x1000,
        MissingFile = 0x2000,
        ExceptionAccessingFile = 0x4000,
        InvalidCommandLineOption = 0x8000,

        // Non-fatal conditions
        RuleNotApplicableToTarget = 0x10000000,
        TargetNotValidToAnalyze   = 0x20000000,

        Nonfatal = 0x30000000
    }
}


text:
<?php
    require_once './utils.php';
    require_once './oxdlibrary/Uma_rp_get_rpt.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    $baseUrl = __DIR__;
    $oxdJSON = file_get_contents($baseUrl . '/oxdId.json');
    $oxdObject = json_decode($oxdJSON);
    $oxdRpConfig = json_decode(file_get_contents($baseUrl . '/oxdlibrary/oxd-rp-settings.json'));
    try{
        if($oxdRpConfig->conn_type == "local"){
    //	    This is for OXD Socket
            $uma_rp_get_rpt = new Uma_rp_get_rpt();
        }
        else if($oxdRpConfig->conn_type == "web"){
    //	    This is for OXD-TO-HTTP
            $uma_rp_get_rpt = new Uma_rp_get_rpt($config);
        }
        $uma_rp_get_rpt->setRequest_oxd_id($oxdObject->oxd_id);
        $uma_rp_get_rpt->setRequest_ticket("8d736e57-e407-4ec2-ab8b-92df70d90edb");

        if($oxdRpConfig->conn_type == "local"){
            $uma_rp_get_rpt->setRequest_protection_access_token(getClientProtectionAccessToken());
        }else if($oxdRpConfig->conn_type == "web"){
            $uma_rp_get_rpt->setRequest_protection_access_token(getClientProtectionAccessToken($config));
        }
        $uma_rp_get_rpt->request();
        echo $uma_rp_get_rpt->getResponseJSON();
    }
    catch(Exception $e){
        echo "{\"error\":\"".$e->getMessage()."\"}";
    }
?>


text:
package co.edu.eafit.solver.lib.rootfinding.methods.open;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;

import expr.SyntaxException;

import org.json.JSONException;
import org.json.JSONObject;

import co.edu.eafit.solver.lib.rootfinding.functions.Function;
import co.edu.eafit.solver.lib.rootfinding.methods.enums.EFailureCauses;
import co.edu.eafit.solver.lib.rootfinding.methods.enums.EParameter;
import co.edu.eafit.solver.lib.rootfinding.methods.enums.EResultProcess;
import co.edu.eafit.solver.lib.rootfinding.methods.enums.EResults;
import co.edu.eafit.solver.lib.rootfinding.methods.exceptions.InvalidParameterException;

/**
 * Multiple Roots is a derivative of Fixed Point, it is intended to work where Newton's and
 * Secant could fail, given an equation that can be expressed in the form f(x) = (x-xv)^m q(x)
 * we can tell that xv is a multiple root.
 *
 * As the root value can be repeated in some cases, we would have denominators aproaching zero,
 * here is where this method comes handy, it finds a root of a given multiplicity using the
 * g function g(x) = x - f(x)*f'(x) / (f'(x)^2 - f(x)*f''(x)).
 *
 * In this method we have to give two derivatives, and it's convergence time isn't great, but
 * it is useful when it comes to solve problems where Secant and Newton have failed.
 * @author halzate93
 * https://github.com/halzate93/solver/wiki/Multiple-Roots
 */
public class MultipleRoots extends FixedPoint {

	private Function df;
	private Function d2f;

	protected float denominator;
	protected float dy;
	protected float d2y;

	@Override
	protected void firstStep() throws SyntaxException{
		super.firstStep();
		dy = df.evaluate(xn);
		d2y = d2f.evaluate(xn);
		denominator = ((float) Math.pow(dy, 2f)) - y*d2y;
	}

	protected float getNextApproximation(JSONObject[] info) throws SyntaxException{
		info[0].put(EResultProcess.Dfx.toString(), dy);
		info[0].put(EResultProcess.D2fx.toString(), d2y);
		info[0].put(EResultProcess.Denominator.toString(), denominator);
		return xn - (y*dy)/denominator;
	}

	@Override
	protected void updateStatus() throws SyntaxException{
		super.updateStatus();
		dy = df.evaluate(xn);
		d2y = d2f.evaluate(xn);
		denominator = ((float) Math.pow(dy, 2f)) - y*d2y;
	}

	@Override
	protected boolean checkExit(){
		if(!super.checkExit())
			return false;
		else if(denominator == 0){
			result = new SimpleEntry<EResults, String>(EResults.Failure,
					EFailureCauses.Denominator.toString());
			return false;
		} else
			return true;
	}

	@Override
	public void setup(JSONObject params) throws InvalidParameterException{
		super.setup(params);
		if(params.has(EParameter.Df.toString())){
			String value = params.getString(EParameter.Df.toString());
			try {
				df = new Function(value);
			} catch (JSONException e) {
				e.printStackTrace();
			} catch (SyntaxException e) {
				throw new InvalidParameterException(EParameter.Df, value);
			}
		}
		if(params.has(EParameter.D2f.toString())){
			String value = params.getString(EParameter.D2f.toString());
			try {
				d2f = new Function(value);
			} catch (JSONException e) {
				e.printStackTrace();
			} catch (SyntaxException e) {
				throw new InvalidParameterException(EParameter.D2f, value);
			}
		}
	}

	@Override
	public EParameter[] getRequiredParameters(){
		ArrayList<EParameter> required = new ArrayList<>( Arrays.asList(
				super.getRequiredParameters()));
		required.remove(EParameter.G);
		required.add(EParameter.Df);
		required.add(EParameter.D2f);
		return required.toArray(new EParameter[]{});
	}

	@Override
	public EParameter[] checkParameters(){
		ArrayList<EParameter> missing = new ArrayList<>(Arrays.asList(super.checkParameters()));
		missing.remove(EParameter.G);
		if(df == null){
			missing.add(EParameter.Df);
		}
		if(d2f == null){
			missing.add(EParameter.D2f);
		}
		return missing.toArray(new EParameter[]{});
	}

	public Function getDerivative() {
		return df;
	}

	public Function getSecondDerivative() {
		return d2f;
	}
}


text:
#include <jni.h>

#include <android/log.h>

#include <cstdlib>

#include "opus.h"  // NOLINT
#include "opus_multistream.h"  // NOLINT

#define LOG_TAG "libopus_native"
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
                                             __VA_ARGS__))

#define FUNC(RETURN_TYPE, NAME, ...) \
  extern "C" { \
  JNIEXPORT RETURN_TYPE \
    Java_com_google_android_exoplayer_ext_opus_OpusDecoder_ ## NAME \
      (JNIEnv* env, jobject thiz, ##__VA_ARGS__);\
  } \
  JNIEXPORT RETURN_TYPE \
    Java_com_google_android_exoplayer_ext_opus_OpusDecoder_ ## NAME \
      (JNIEnv* env, jobject thiz, ##__VA_ARGS__)\

jint JNI_OnLoad(JavaVM* vm, void* reserved) {
  JNIEnv* env;
  if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
    return -1;
  }
  return JNI_VERSION_1_6;
}

static int channelCount;

FUNC(jlong, opusInit, jint sampleRate, jint channelCount, jint numStreams,
     jint numCoupled, jint gain, jbyteArray jStreamMap) {
  int status = OPUS_INVALID_STATE;
  ::channelCount = channelCount;
  jbyte* streamMapBytes = env->GetByteArrayElements(jStreamMap, 0);
  uint8_t* streamMap = reinterpret_cast<uint8_t*>(streamMapBytes);
  OpusMSDecoder* decoder = opus_multistream_decoder_create(
      sampleRate, channelCount, numStreams, numCoupled, streamMap, &status);
  env->ReleaseByteArrayElements(jStreamMap, streamMapBytes, 0);
  if (!decoder || status != OPUS_OK) {
    LOGE("Failed to create Opus Decoder; status=%s", opus_strerror(status));
    return 0;
  }
  status = opus_multistream_decoder_ctl(decoder, OPUS_SET_GAIN(gain));
  if (status != OPUS_OK) {
    LOGE("Failed to set Opus header gain; status=%s", opus_strerror(status));
    return 0;
  }
  return reinterpret_cast<intptr_t>(decoder);
}

FUNC(jint, opusDecode, jlong jDecoder, jobject jInputBuffer, jint inputSize,
     jobject jOutputBuffer, jint outputSize) {
  OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
  const uint8_t* inputBuffer =
      reinterpret_cast<const uint8_t*>(
          env->GetDirectBufferAddress(jInputBuffer));
  int16_t* outputBuffer = reinterpret_cast<int16_t*>(
      env->GetDirectBufferAddress(jOutputBuffer));
  int numFrames = opus_multistream_decode(decoder, inputBuffer, inputSize,
                                          outputBuffer, outputSize, 0);
  return (numFrames < 0) ? numFrames : numFrames * 2 * channelCount;
}

FUNC(void, opusClose, jlong jDecoder) {
  OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
  opus_multistream_decoder_destroy(decoder);
}

FUNC(void, opusReset, jlong jDecoder) {
  OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
  opus_multistream_decoder_ctl(decoder, OPUS_RESET_STATE);
}

FUNC(jstring, opusGetErrorMessage, jint errorCode) {
  return env->NewStringUTF(opus_strerror(errorCode));
}


text:
<?php
class Initial extends CakeMigration {

/**
 * Migration description
 *
 * @var string
 */
	public $description = '';

/**
 * Actions to be performed
 *
 * @var array $migration
 */
	public $migration = array(
		'up' => array(
			'create_table' => array(
				'accessibilityequipments' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
				),
				'addresses' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'latitude' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
					'longitude' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
					'street' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
					'zipcode' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
					'district_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
						'fk_address_district_id' => array('column' => 'district_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
				),
				'advancedclasses' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
				),
				'advancedclasses_schoolbranches' => array(
					'schoolbranch_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'advancedclass_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('schoolbranch_id', 'advancedclass_id'), 'unique' => 1),
						'fk_schoolbranch_subject_advancedcoursesubjects_id' => array('column' => 'advancedclass_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'districts' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
				),
				'equipments' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
				),
				'foreignlanguages' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'foreignlanguages_schoolbranches' => array(
					'schoolbranch_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'foreignlanguage_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('schoolbranch_id', 'foreignlanguage_id'), 'unique' => 1),
						'schoolbranch_foreignlanguage_foreignlanguages_id' => array('column' => 'foreignlanguage_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'grades' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'boys' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'boysforeignnativelanguage' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'girls' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'girlsforeignnativelanguage' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'grade' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'institutionproviders' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'description' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'jobtitles' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'partners' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'projectgroups' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'description' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'projectgroups_schoolbranches' => array(
					'schoolbranch_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'projectgroup_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('schoolbranch_id', 'projectgroup_id'), 'unique' => 1),
						'fk_schoolbranch_projectgroup_projectgroups_id' => array('column' => 'projectgroup_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schoolbranches' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'duallearningdecription' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'school_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'schooltype_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
						'fk_schoolbranch_schooltype_id' => array('column' => 'schooltype_id', 'unique' => 0),
						'fk_schoolbranch_school_id' => array('column' => 'school_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schoolbranches_specialactivities' => array(
					'schoolbranch_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'specialactivity_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('schoolbranch_id', 'specialactivity_id'), 'unique' => 1),
						'schoolbranch_specialactivity_specialactivities_id' => array('column' => 'specialactivity_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'bsn' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'unique', 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'meal' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'phonenumber' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'remarks' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'schoolnumber' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'wwwaddress' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'institutionprovider_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'address_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
						'bsn_2' => array('column' => 'bsn', 'unique' => 1),
						'fk_school_provider_id' => array('column' => 'institutionprovider_id', 'unique' => 0),
						'fk_school_address_id' => array('column' => 'address_id', 'unique' => 0),
						'bsn' => array('column' => 'bsn', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_accessibilityequipments' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'accessibilityequipment_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'accessibilityequipment_id'), 'unique' => 1),
						'scholaccessibilityequipmentccessibilityequipmentid' => array('column' => 'accessibilityequipment_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_equipments' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'equipment_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'equipment_id'), 'unique' => 1),
						'fk_school_equipment_equipment_id' => array('column' => 'equipment_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_foreignlanguages' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'foreignlanguage_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'foreignlanguage_id'), 'unique' => 1),
						'fk_school_foreignlanguage_foreignlanguages_id' => array('column' => 'foreignlanguage_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_grades' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'grade_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'grade_id'), 'unique' => 1),
						'fk_school_grade_grades_id' => array('column' => 'grade_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_staffs' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'staff_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'staff_id'), 'unique' => 1),
						'fk_school_staff_staff_id' => array('column' => 'staff_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schools_subjects' => array(
					'school_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'subject_id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'indexes' => array(
						'PRIMARY' => array('column' => array('school_id', 'subject_id'), 'unique' => 1),
						'fk_school_advancedclass_advancedclass_id' => array('column' => 'subject_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'schooltypes' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'specialactivities' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'staffs' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'count' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
					'jobtitle_id' => array('type' => 'biginteger', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
						'fk_staff_jobtitle_id' => array('column' => 'jobtitle_id', 'unique' => 0),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
				'subjects' => array(
					'id' => array('type' => 'biginteger', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
					'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
					'indexes' => array(
						'PRIMARY' => array('column' => 'id', 'unique' => 1),
					),
					'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB'),
				),
			),
		),
		'down' => array(
			'drop_table' => array(
				'accessibilityequipments', 'addresses', 'advancedclasses', 'advancedclasses_schoolbranches', 'districts', 'equipments', 'foreignlanguages', 'foreignlanguages_schoolbranches', 'grades', 'institutionproviders', 'jobtitles', 'partners', 'projectgroups', 'projectgroups_schoolbranches', 'schoolbranches', 'schoolbranches_specialactivities', 'schools', 'schools_accessibilityequipments', 'schools_equipments', 'schools_foreignlanguages', 'schools_grades', 'schools_staffs', 'schools_subjects', 'schooltypes', 'specialactivities', 'staffs', 'subjects'
			),
		),
	);

/**
 * Before migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 */
	public function before($direction) {
		return true;
	}

/**
 * After migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 */
	public function after($direction) {
		return true;
	}
}


text:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <parent>
	<groupId>org.apache.juddi</groupId>
	<artifactId>juddi-style-parent</artifactId>
	<version>1.0.2-SNAPSHOT</version>
	<relativePath>../../pom.xml</relativePath>
  </parent>
  <artifactId>juddi-docbook-style</artifactId>
  <packaging>jdocbook-style</packaging>
  <name>Apache jUDDI Documentation Style</name>
  <description>CSS and images to style XHTML Apache jUDDI Documentation.</description>
  <pluginRepositories>
		<pluginRepository>
			<id>repository.jboss.org</id>
			<name>JBoss Repository</name>
			<layout>default</layout>
			<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
  <build>
    <plugins>
      <plugin>
        <groupId>org.jboss.maven.plugins</groupId>
        <artifactId>maven-jdocbook-style-plugin</artifactId>
        <version>2.0.0</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>

    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-webdav</artifactId>
        <version>1.0-beta-2</version>
      </extension>
    </extensions>
  </build>

</project>


text:
from zeit.retresco.tag import Tag
import json
import mock
import zeit.cms.browser.interfaces
import zeit.cms.tagging.source
import zeit.cms.testing
import zeit.retresco.testing
import zope.component
import zope.publisher.browser

class TestWhitelist(zeit.retresco.testing.FunctionalTestCase):
    """Testing ..whitelist.Whitelist"""

    @property
    def whitelist(self):
        from ..whitelist import Whitelist
        return Whitelist()

    def test_get_creates_tag_from_code(self):
        tag = self.whitelist.get(u'person☃Wolfgang')
        self.assertEqual('Wolfgang', tag.label)
        self.assertEqual('person', tag.entity_type)

    def test_get_returns_None_for_old_uuids(self):
        self.assertEqual(
            None, self.whitelist.get('66ef0e83-f760-43fa-ae24-8bf9ce14ebf0'))

    def test_search_uses_TMS_get_keywords_for_searching(self):
        with mock.patch('zeit.retresco.connection.TMS.get_keywords') as kw:
            self.whitelist.search('Foo-Bar')
        self.assertEqual('Foo-Bar', kw.call_args[0][0])

class TestWhitelistLocationAutocomplete(
        zeit.cms.testing.ZeitCmsBrowserTestCase):
    """Testing ..whitelist.Whitelist.locations()."""

    layer = zeit.retresco.testing.ZCML_LAYER

    def test_search_for_locations(self):
        request = zope.publisher.browser.TestRequest(
            skin=zeit.cms.browser.interfaces.ICMSLayer,
            SERVER_URL='http://localhost/++skin++vivi')
        url = zope.component.getMultiAdapter(
            (zeit.cms.tagging.source.locationSource(None), request),
            zeit.cms.browser.interfaces.ISourceQueryURL)
        with mock.patch('zeit.retresco.connection.TMS.get_locations') as gl:
            gl.return_value = [Tag(u'Schweiz', u'location'),
                               Tag(u'Frankreich', u'location')]
            b = self.browser
            b.open(url + '?term=ei')
            result = json.loads(b.contents)
        self.assertEqual([{u'label': u'Schweiz',
                           u'value': u'tag://location\\u2603Schweiz'},
                          {u'label': u'Frankreich',
                           u'value': u'tag://location\\u2603Frankreich'}],
                         result)


text:
package de.ludwig.objstreamer;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.EnumSet;

/**
 * objectchunk parent:3214 childs:3443 fieldName:334 fqn:2312 values ....
 * objectchunk
 *
 * Every ObjectChunk is serialized as a Head-Section and a Value-Section. The
 * Head-Section holds the references to the values stored in the Value-Section.
 *
 * The Head-Section starts with {@link FileConstants#CHUNK_START}. The
 * Value-Section starts with {@link FileConstants#VALUES_START}.
 *
 * @author Daniel
 *
 */
public class ObjStreamWriter {

	private final static EnumSet<FileConstants> FIELDS = EnumSet.of(
			FileConstants.PARENT, FileConstants.FIELD_NAME);

	public void write(ObjStreamer stream, File out) {
		RandomAccessFile raf = null;

		try {
			raf = new RandomAccessFile(out, "rw");

			long currentChunkStartPtr = 0l;
			ObjectChunk rootChunk = stream.getObjectGraphRoot();

			write(raf, currentChunkStartPtr, rootChunk);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (raf != null) {
				try {
					raf.close();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
	}

	private void write(RandomAccessFile raf, long currentChunkStartPtr,
			ObjectChunk chunk) throws IOException {

		writeChunks(raf, currentChunkStartPtr, chunk);

		// process childs
		for (ObjectChunk oc : chunk.getChilds()) {
			// TODO parse in ptr of parent chunk
			write(raf, raf.getFilePointer(), oc);
		}

	}

	/**
	 * Write the given field and the reference to the head section.
	 *
	 * @param raf
	 * @param chunk
	 * @param currentChunkStartPtr
	 * @param fieldNum
	 * @throws IOException
	 */
	private void writeChunks(RandomAccessFile raf, long currentChunkStartPtr, ObjectChunk chunk) throws IOException {
		raf.writeBytes(FileConstants.CHUNK_START.val);
		raf.writeBytes(FileConstants.PARENT.val);
		raf.writeLong(-1);
		raf.writeBytes(FileConstants.FIELD_NAME.val);
		raf.writeLong(-1);
		// TODO further params

		// write values start
		raf.writeBytes(FileConstants.VALUES_START.val);

		// write values, store value of the position where we write the value to
//		long ptr = raf.getFilePointer();

		for(FileConstants fc : FIELDS){
			writeFieldValueAndRef(raf, chunk, fc, currentChunkStartPtr);
		}

	}

	private void writeFieldValueAndRef(RandomAccessFile raf, ObjectChunk chunk,
			FileConstants field, long currentChunkStartPtr) throws IOException {
		switch (field) {
		case FIELD_NAME:
			String fieldName = chunk.getFieldName();
			if (fieldName != null) {
				long ptr = raf.getFilePointer();
				raf.writeBytes(fieldName);
				writeFieldRef(raf, currentChunkStartPtr, field, ptr);
			}
			break;

		case PARENT:
			chunk.getParent();
			break;
		default:
			break;
		}
	}

	private void writeFieldRef(RandomAccessFile raf, long currentChunkStartPtr, FileConstants field, long valuePtr) throws IOException{
		final long endPtr = raf.getFilePointer();
		final long computeWriteRefOffset = computeWriteRefOffset(currentChunkStartPtr, field);

		// reference position
		raf.seek(computeWriteRefOffset);
		// finally write the reference, overwrite the default -1
		raf.writeLong(valuePtr);
		raf.seek(endPtr);
	}

	private long computeWriteRefOffset(long currentChunkStartPtr, FileConstants field){
		long writePos = currentChunkStartPtr
				+ FileConstants.CHUNK_START.byteLength();

		for(FileConstants fc : FIELDS){
			writePos += fc.byteLength();
			if(fc.equals(field)){
				break;
			}
			writePos += 8;
		}

		return writePos;
	}
}


text:
"""Verify that all OSF Storage files have Glacier backups and parity files,
creating any missing backups.

TODO: Add check against Glacier inventory
Note: Must have par2 installed to run
"""

from __future__ import division

import gc
import os
import math
import hashlib
import logging

import pyrax

from modularodm import Q
from boto.glacier.layer2 import Layer2
from pyrax.exceptions import NoSuchObject

from framework.celery_tasks import app as celery_app

from website.app import init_app
from website.files import models

from scripts import utils as scripts_utils
from scripts.osfstorage import utils as storage_utils
from scripts.osfstorage import settings as storage_settings

container_primary = None
container_parity = None
vault = None
audit_temp_path = None

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
logging.getLogger('boto').setLevel(logging.CRITICAL)

def delete_temp_file(version):
    path = os.path.join(audit_temp_path, version.location['object'])
    try:
        os.remove(path)
    except OSError:
        pass

def download_from_cloudfiles(version):
    path = os.path.join(audit_temp_path, version.location['object'])
    if os.path.exists(path):
        # we cannot assume the file is valid and not from a previous failure.
        delete_temp_file(version)
    try:
        obj = container_primary.get_object(version.location['object'])
        with open(path, 'wb') as fp:
            hasher = hashlib.sha256()
            fetcher = obj.fetch(chunk_size=262144000)  # 256mb chunks
            while True:
                try:
                    chunk = next(fetcher)
                except StopIteration:
                    break
                hasher.update(chunk)
                fp.write(chunk)
        if hasher.hexdigest() != version.metadata['sha256']:
            raise Exception('SHA256 mismatch, cannot continue')
        return path
    except NoSuchObject as err:
        logger.error('*** FILE NOT FOUND ***')
        logger.error('Exception:')
        logger.exception(err)
        logger.error('Version info:')
        logger.error(version.to_storage())
        return None

def ensure_glacier(version, dry_run):
    if version.metadata.get('archive'):
        return
    logger.warn('Glacier archive for version {0} not found'.format(version._id))
    if dry_run:
        return
    file_path = download_from_cloudfiles(version)
    if file_path:
        glacier_id = vault.upload_archive(file_path, description=version.location['object'])
        version.metadata['archive'] = glacier_id
        version.save()

def check_parity_files(version):
    index = list(container_parity.list_all(prefix='{0}.par2'.format(version.location['object'])))
    vols = list(container_parity.list_all(prefix='{0}.vol'.format(version.location['object'])))
    return len(index) == 1 and len(vols) >= 1

def ensure_parity(version, dry_run):
    if check_parity_files(version):
        return
    logger.warn('Parity files for version {0} not found'.format(version._id))
    if dry_run:
        return
    file_path = download_from_cloudfiles(version)
    if file_path:
        parity_paths = storage_utils.create_parity_files(file_path)
        for parity_path in parity_paths:
            container_parity.create(parity_path)
            os.remove(parity_path)
        if not check_parity_files(version):
            logger.error('Parity files for version {0} not found after update'.format(version._id))

def ensure_backups(version, dry_run):
    ensure_glacier(version, dry_run)
    ensure_parity(version, dry_run)
    delete_temp_file(version)

def glacier_targets():
    return models.FileVersion.find(
        Q('status', 'ne', 'cached') &
        Q('location.object', 'exists', True) &
        Q('metadata.archive', 'eq', None)
    )

def parity_targets():
    # TODO: Add metadata.parity information from wb so we do not need to check remote services
    return models.FileVersion.find(
        Q('status', 'ne', 'cached') &
        Q('location.object', 'exists', True)
        # & Q('metadata.parity', 'eq', None)
    )

def audit(targets, num_of_workers, worker_id, dry_run):
    maxval = math.ceil(targets.count() / num_of_workers)
    target_iterator = targets.iterator()
    idx = 0
    last_progress = -1
    for version in target_iterator:
        if hash(version._id) % num_of_workers == worker_id:
            if version.size == 0:
                continue
            ensure_backups(version, dry_run)
            idx += 1
            progress = int(idx / maxval * 100)
            if last_progress < 100 and last_progress < progress:
                logger.info(str(progress) + '%')
                last_progress = progress
                gc.collect()

@celery_app.task(name='scripts.osfstorage.files_audit')
def main(num_of_workers=0, worker_id=0, glacier=True, parity=True, dry_run=True):
    global container_primary
    global container_parity
    global vault
    global audit_temp_path

    # Set up storage backends
    init_app(set_backends=True, routes=False)

    try:
        # Authenticate to Rackspace
        pyrax.settings.set('identity_type', 'rackspace')
        pyrax.set_credentials(
            storage_settings.USERNAME,
            storage_settings.API_KEY,
            region=storage_settings.REGION
        )
        container_primary = pyrax.cloudfiles.get_container(storage_settings.PRIMARY_CONTAINER_NAME)
        container_parity = pyrax.cloudfiles.get_container(storage_settings.PARITY_CONTAINER_NAME)

        # Connect to AWS
        layer2 = Layer2(
            aws_access_key_id=storage_settings.AWS_ACCESS_KEY,
            aws_secret_access_key=storage_settings.AWS_SECRET_KEY,
        )
        vault = layer2.get_vault(storage_settings.GLACIER_VAULT)

        # Log to file
        if not dry_run:
            scripts_utils.add_file_logger(logger, __file__, suffix=worker_id)

        audit_temp_path = os.path.join(storage_settings.AUDIT_TEMP_PATH, str(worker_id))
        if not dry_run:
            try:
                os.makedirs(audit_temp_path)
            except OSError:
                pass

        if glacier:
            logger.info('glacier audit start')
            audit(glacier_targets(), num_of_workers, worker_id, dry_run)
            logger.info('glacier audit complete')

        if parity:
            logger.info('parity audit start')
            audit(parity_targets(), num_of_workers, worker_id, dry_run)
            logger.info('parity audit complete')

    except Exception as err:
        logger.error('=== Unexpected Error ===')
        logger.exception(err)
        raise err

if __name__ == '__main__':
    import sys
    arg_num_of_workers = int(sys.argv[1])
    arg_worker_id = int(sys.argv[2])
    arg_glacier = 'glacier' in sys.argv
    arg_parity = 'parity' in sys.argv
    arg_dry_run = 'dry' in sys.argv
    main(num_of_workers=arg_num_of_workers, worker_id=arg_worker_id, glacier=arg_glacier, parity=arg_parity, dry_run=arg_dry_run)