Java tutorial
//package com.java2s; /* * Copyright (C) 2014 The Android Open Source Project * * 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. */ public class Main { private static final byte[] NAL_START_CODE = new byte[] { 0, 0, 0, 1 }; /** * Constructs a NAL unit consisting of the NAL start code followed by the specified data. * * @param data An array containing the data that should follow the NAL start code. * @param offset The start offset into {@code data}. * @param length The number of bytes to copy from {@code data} * @return The constructed NAL unit. */ public static byte[] buildNalUnit(byte[] data, int offset, int length) { byte[] nalUnit = new byte[length + NAL_START_CODE.length]; System.arraycopy(NAL_START_CODE, 0, nalUnit, 0, NAL_START_CODE.length); System.arraycopy(data, offset, nalUnit, NAL_START_CODE.length, length); return nalUnit; } }