diff options
Diffstat (limited to 'isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base')
5 files changed, 0 insertions, 283 deletions
diff --git a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/ByteBufferByteChannel.java.svn-base b/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/ByteBufferByteChannel.java.svn-base deleted file mode 100644 index 9f3264b..0000000 --- a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/ByteBufferByteChannel.java.svn-base +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012 Sebastian Annies, Hamburg - * - * 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. - */ -package com.googlecode.mp4parser.util; - -import java.io.EOFException; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.ByteChannel; - -/** - * Creates a <code>ReadableByteChannel</code> that is backed by a <code>ByteBuffer</code>. - */ -public class ByteBufferByteChannel implements ByteChannel { - ByteBuffer byteBuffer; - - public ByteBufferByteChannel(ByteBuffer byteBuffer) { - this.byteBuffer = byteBuffer; - } - - public int read(ByteBuffer dst) throws IOException { - byte[] b = dst.array(); - int r = dst.remaining(); - if (byteBuffer.remaining() >= r) { - byteBuffer.get(b, dst.position(), r); - return r; - } else { - throw new EOFException("Reading beyond end of stream"); - } - } - - public boolean isOpen() { - return true; - } - - public void close() throws IOException { - } - - public int write(ByteBuffer src) throws IOException { - int r = src.remaining(); - byteBuffer.put(src); - return r; - } -} diff --git a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/CastUtils.java.svn-base b/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/CastUtils.java.svn-base deleted file mode 100644 index 2dd011a..0000000 --- a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/CastUtils.java.svn-base +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012 Sebastian Annies, Hamburg - * - * 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. - */ -package com.googlecode.mp4parser.util; - - -public class CastUtils { - /** - * Casts a long to an int. In many cases I use a long for a UInt32 but this cannot be used to allocate - * ByteBuffers or arrays since they restricted to <code>Integer.MAX_VALUE</code> this cast-method will throw - * a RuntimeException if the cast would cause a loss of information. - * - * @param l the long value - * @return the long value as int - */ - public static int l2i(long l) { - if (l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) { - throw new RuntimeException("A cast to int has gone wrong. Please contact the mp4parser discussion group (" + l + ")"); - } - return (int) l; - } -} diff --git a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Math.java.svn-base b/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Math.java.svn-base deleted file mode 100644 index 27fd4b2..0000000 --- a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Math.java.svn-base +++ /dev/null @@ -1,30 +0,0 @@ -package com.googlecode.mp4parser.util; - -public class Math { - public static long gcd(long a, long b) { - while (b > 0) { - long temp = b; - b = a % b; // % is remainder - a = temp; - } - return a; - } - - public static int gcd(int a, int b) { - while (b > 0) { - int temp = b; - b = a % b; // % is remainder - a = temp; - } - return a; - } - - public static long lcm(long a, long b) { - return a * (b / gcd(a, b)); - } - - public static int lcm(int a, int b) { - return a * (b / gcd(a, b)); - } - -} diff --git a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Path.java.svn-base b/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Path.java.svn-base deleted file mode 100644 index a6066c8..0000000 --- a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/Path.java.svn-base +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2012 Sebastian Annies, Hamburg - * - * 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. - */ -package com.googlecode.mp4parser.util; - - -import com.coremedia.iso.IsoFile; -import com.coremedia.iso.boxes.Box; -import com.coremedia.iso.boxes.ContainerBox; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Path { - - private Path() { - } - - static Pattern component = Pattern.compile("(....|\\.\\.)(\\[(.*)\\])?"); - - public static String createPath(Box box) { - return createPath(box, ""); - } - - private static String createPath(Box box, String path) { - if (box instanceof IsoFile) { - return path; - } else { - List<?> boxesOfBoxType = box.getParent().getBoxes(box.getClass()); - int index = boxesOfBoxType.indexOf(box); - path = String.format("/%s[%d]", box.getType(), index) + path; - - return createPath(box.getParent(), path); - } - } - - public static Box getPath(Box box, String path) { - List<Box> all = getPaths(box, path); - return all.isEmpty() ? null : all.get(0); - } - - - public static List<Box> getPaths(Box box, String path) { - if (path.startsWith("/")) { - Box isoFile = box; - while (isoFile.getParent() != null) { - isoFile = isoFile.getParent(); - } - assert isoFile instanceof IsoFile : isoFile.getType() + " has no parent"; - return getPaths(isoFile, path.substring(1)); - } else if (path.isEmpty()) { - return Collections.singletonList(box); - } else { - String later; - String now; - if (path.contains("/")) { - later = path.substring(path.indexOf('/') + 1); - now = path.substring(0, path.indexOf('/')); - } else { - now = path; - later = ""; - } - - Matcher m = component.matcher(now); - if (m.matches()) { - String type = m.group(1); - if ("..".equals(type)) { - return getPaths(box.getParent(), later); - } else { - int index = -1; - if (m.group(2) != null) { - // we have a specific index - String indexString = m.group(3); - index = Integer.parseInt(indexString); - } - List<Box> children = new LinkedList<Box>(); - int currentIndex = 0; - for (Box box1 : ((ContainerBox) box).getBoxes()) { - if (box1.getType().matches(type)) { - if (index == -1 || index == currentIndex) { - children.addAll(getPaths(box1, later)); - } - currentIndex++; - } - } - return children; - } - } else { - throw new RuntimeException(now + " is invalid path."); - } - } - - } - - - public static boolean isContained(Box box, String path) { - assert path.startsWith("/") : "Absolute path required"; - return getPaths(box, path).contains(box); - } -} diff --git a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/UUIDConverter.java.svn-base b/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/UUIDConverter.java.svn-base deleted file mode 100644 index 635e4c1..0000000 --- a/isoparser/src/main/java/com/googlecode/mp4parser/util/.svn/text-base/UUIDConverter.java.svn-base +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012 Sebastian Annies, Hamburg - * - * 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. - */ -package com.googlecode.mp4parser.util; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.UUID; - -/** - * UUID from/to byte array. - */ -public class UUIDConverter { - public static byte[] convert(UUID uuid) { - - long msb = uuid.getMostSignificantBits(); - long lsb = uuid.getLeastSignificantBits(); - byte[] buffer = new byte[16]; - - for (int i = 0; i < 8; i++) { - buffer[i] = (byte) (msb >>> 8 * (7 - i)); - } - for (int i = 8; i < 16; i++) { - buffer[i] = (byte) (lsb >>> 8 * (7 - i)); - } - - return buffer; - - } - - public static UUID convert(byte[] uuidBytes) { - ByteBuffer b = ByteBuffer.wrap(uuidBytes); - b.order(ByteOrder.BIG_ENDIAN); - return new UUID(b.getLong(), b.getLong()); - } -} |