diff options
Diffstat (limited to 'cmpcj/src/de/schwarzrot/cmpc/util')
10 files changed, 0 insertions, 846 deletions
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java deleted file mode 100644 index 620c373..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaClientExecutor.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import de.schwarzrot.cmpc.domain.Media; - - -public interface MediaClientExecutor { - public void playMedia(Media m); -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java deleted file mode 100644 index a719032..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaComparator.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.util.Comparator; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaComparator implements Comparator<Media> { - @Override - public int compare(Media a, Media b) { - if (a.getType() == b.getType()) - return a.getName().compareToIgnoreCase(b.getName()); - return a.getType().ordinal() - b.getType().ordinal(); - } -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java deleted file mode 100644 index 8cdea21..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaExecutor.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import javax.swing.JTable; -import ca.odell.glazedlists.EventList; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaExecutor extends MouseAdapter { - public MediaExecutor(JTable table, EventList<Media> list, MediaClientExecutor mce) { - this.table = table; - this.list = list; - executor = mce; - } - - - @Override - public void mouseClicked(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) { - int i = table.rowAtPoint(e.getPoint()); - Media m = list.get(i); - - executor.playMedia(m); - } - } - - private JTable table; - private EventList<Media> list; - private MediaClientExecutor executor; -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java deleted file mode 100644 index 18820cf..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaForTypeMatcher.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import ca.odell.glazedlists.matchers.Matcher; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaForTypeMatcher implements Matcher<Media> { - public MediaForTypeMatcher(Collection<Media.SupportedMediaType> mediaTypes) { - this.mediaTypes.addAll(mediaTypes); - } - - - @Override - public boolean matches(Media m) { - if (m == null) - return false; - if (mediaTypes.isEmpty()) - return true; - Media.SupportedMediaType mt = m.getType(); - - return mediaTypes.contains(mt); - } - - private Set<Media.SupportedMediaType> mediaTypes = new HashSet<Media.SupportedMediaType>(); -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java deleted file mode 100644 index 983fdd3..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaListLoader.java Created: Author: <a - * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend - * (client) part of compound media player uses external players to play the - * media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any - * workstation without the need to export or mount shares. cmps is an easy to - * use backend with a (ready to use) HTML-interface. Additionally the backend - * supports authentication via HTTP-digest authorization. cmpc is a client with - * vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under - * Creative Commons by-sa For details see - * http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at - * http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.net.ConnectException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Date; -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import de.schwarzrot.cmpc.domain.Media; -import de.schwarzrot.cmpc.domain.PlayList; - - -public class MediaListLoader implements Runnable { - public EventList<Media> getMediaPool() { - return mediaPool; - } - - - public void loadMedia(String hostname, int port) { - this.hostName = hostname; - this.port = port; - - Thread backgroundThread = new Thread(this); - - backgroundThread.setName("load media list from " + hostName); - backgroundThread.setDaemon(true); - backgroundThread.start(); - } - - - @Override - public void run() { - URL request = null; - Date start, end; - - try { - start = new Date(); - request = new URL("http", hostName, port, "/?format=json"); - URLConnection conn = request.openConnection(); - final PlayList firstPlaylist = jsonParser.parseListChunk(conn.getInputStream()); - - mediaPool.getReadWriteLock().writeLock().lock(); - for (Media m : firstPlaylist.getResults()) { - mediaPool.add(m); - } - mediaPool.getReadWriteLock().writeLock().unlock(); - - end = new Date(); - System.out.println("processing of first playlist-part took " + (end.getTime() - start.getTime()) + " ms."); - PlayList next; - long total = firstPlaylist.getTotal(); - long n = firstPlaylist.getResults().size(); - String uri; - - start = new Date(); - try { - while (n < total) { - uri = String.format("/?start=%d&limit=%d&format=json", n, 100); - request = new URL("http", hostName, port, uri); - conn = request.openConnection(); - next = jsonParser.parseListChunk(conn.getInputStream()); - mediaPool.getReadWriteLock().writeLock().lock(); - for (Media m : next.getResults()) { - mediaPool.add(m); - } - mediaPool.getReadWriteLock().writeLock().unlock(); - n += next.getResults().size(); - Thread.sleep(10); - } - } catch (Throwable t) { - System.out.println("Oups, media list contains now #" + mediaPool.size() + " entries."); - System.err.println("Error on chunk #" + n); - t.printStackTrace(); - } finally { - try { - mediaPool.getReadWriteLock().writeLock().unlock(); - } catch (Throwable t) { - } - } - end = new Date(); - System.out.println("processing of rest of playlist took " + (end.getTime() - start.getTime()) + " ms."); - } catch (ConnectException ce) { - System.out.println("media server " + hostName + " is not available ..."); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - try { - mediaPool.getReadWriteLock().writeLock().unlock(); - } catch (Throwable t) { - } - } - } - - private String hostName; - private int port; - private MedialistParser jsonParser = new MedialistParser(); - private EventList<Media> mediaPool = new BasicEventList<Media>(); -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java deleted file mode 100644 index de93246..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaPool2TypeList.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.TransformedList; -import ca.odell.glazedlists.event.ListEvent; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaPool2TypeList extends TransformedList<Media, Media.SupportedMediaType> { - public MediaPool2TypeList(EventList<Media> source) { - super(source); - source.addListEventListener(this); - } - - - @Override - public Media.SupportedMediaType get(int index) { - Media m = source.get(index); - - return m.getType(); - } - - - @Override - public void listChanged(ListEvent<Media> listChanges) { - updates.forwardEvent(listChanges); - } - - - @Override - protected boolean isWritable() { - return false; - } -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java deleted file mode 100644 index d427e83..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaTableFormat.java Created: Author: <a - * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend - * (client) part of compound media player uses external players to play the - * media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any - * workstation without the need to export or mount shares. cmps is an easy to - * use backend with a (ready to use) HTML-interface. Additionally the backend - * supports authentication via HTTP-digest authorization. cmpc is a client with - * vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under - * Creative Commons by-sa For details see - * http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at - * http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import ca.odell.glazedlists.gui.TableFormat; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaTableFormat implements TableFormat<Media> { - @Override - public int getColumnCount() { - return 5; - } - - - @Override - public String getColumnName(int column) { - switch (column) { - case 0: - return "Type"; - case 1: - return "Format"; - case 2: - return "Width"; - case 3: - return "Height"; - case 4: - return "Name"; - default: - throw new IllegalStateException(); - } - } - - - @Override - public Object getColumnValue(Media m, int column) { - switch (column) { - case 0: - return m.getType(); - case 1: - return m.getFormat(); - case 2: - return m.getWidth(); - case 3: - return m.getHeight(); - case 4: - return m.getName(); - default: - throw new IllegalStateException(); - } - } - - - public int getColumnWidth(int column) { - switch (column) { - case 0: - return 80; - case 1: - return 100; - case 2: - return 60; - case 3: - return 60; - case 4: - return -1; - default: - throw new IllegalStateException(); - } - } -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java deleted file mode 100644 index aa035d9..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaTextFilterator.java Created: Author: <a - * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend - * (client) part of compound media player uses external players to play the - * media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any - * workstation without the need to export or mount shares. cmps is an easy to - * use backend with a (ready to use) HTML-interface. Additionally the backend - * supports authentication via HTTP-digest authorization. cmpc is a client with - * vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under - * Creative Commons by-sa For details see - * http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at - * http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.util.List; -import ca.odell.glazedlists.TextFilterator; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaTextFilterator implements TextFilterator<Media> { - @Override - public void getFilterStrings(List<String> baseList, Media m) { - baseList.add(m.getName()); - baseList.add(m.getSearch()); - baseList.add(m.getFormat()); - } -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java deleted file mode 100644 index bde865a..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * ======================== legal notice ====================== - * - * File: MediaTypeSelect.java Created: Author: <a - * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend - * (client) part of compound media player uses external players to play the - * media - * - * CMP - compound media player - * - * is a client/server mediaplayer intended to play any media from any - * workstation without the need to export or mount shares. cmps is an easy to - * use backend with a (ready to use) HTML-interface. Additionally the backend - * supports authentication via HTTP-digest authorization. cmpc is a client with - * vdr-like osd-menues. - * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under - * Creative Commons by-sa For details see - * http://creativecommons.org/licenses/by-sa/3.0/ - * - * The cmp project's homepage is at - * http://projects.vdr-developer.org/projects/cmp - * - * -------------------------------------------------------------- - */ -package de.schwarzrot.cmpc.util; - - -import java.awt.Color; -import java.awt.Component; -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.net.URL; -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.UniqueList; -import ca.odell.glazedlists.matchers.AbstractMatcherEditor; -import ca.odell.glazedlists.matchers.Matcher; -import ca.odell.glazedlists.swing.DefaultEventListModel; -import ca.odell.glazedlists.swing.DefaultEventSelectionModel; -import de.schwarzrot.cmpc.domain.Media; - - -public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements ListSelectionListener { - public class MediaTypeCellRenderer extends JLabel implements ListCellRenderer { - private static final long serialVersionUID = 713L; - - - public MediaTypeCellRenderer() { - loadImages(); - } - - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, - boolean cellHasFocus) { - ImageIcon icon = null; - - if (isSelected) { - setBackground(list.getSelectionBackground()); - setForeground(list.getSelectionForeground()); - icon = selImages[((Media.SupportedMediaType) value).ordinal()]; - } else { - setBackground(list.getBackground()); - setForeground(list.getForeground()); - icon = stdImages[((Media.SupportedMediaType) value).ordinal()]; - } - setSize(110, 110); - setHorizontalAlignment(JLabel.CENTER); - - if (icon != null) { - setIcon(icon); - setText(""); - } else { - setText(value.toString()); - } - return this; - } - - - protected void loadImages() { - BufferedImage img = null; - ClassLoader cl = getClass().getClassLoader(); - URL url; - - stdImages = new ImageIcon[iconFiles.length]; - for (int i = 0; i < iconFiles.length; ++i) { - try { - url = cl.getResource(iconFiles[i]); - - img = ImageIO.read(url); - stdImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); - } catch (Throwable t) { - System.err.println("failed to read image from " + iconFiles[i]); - t.printStackTrace(); - } - } - - selImages = new ImageIcon[activeIconFiles.length]; - for (int i = 0; i < activeIconFiles.length; ++i) { - try { - url = cl.getResource(activeIconFiles[i]); - - img = ImageIO.read(url); - selImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); - } catch (Throwable t) { - System.err.println("failed to read image from " + activeIconFiles[i]); - t.printStackTrace(); - } - } - } - - ImageIcon[] stdImages; - ImageIcon[] selImages; - } - - - public MediaTypeSelect(EventList<Media> source) { - EventList<Media.SupportedMediaType> mediaTypeNonUnique = new MediaPool2TypeList(source); - - mediaTypeList = new UniqueList<Media.SupportedMediaType>(mediaTypeNonUnique); - DefaultEventListModel<Media.SupportedMediaType> mediaTypeListModel = new DefaultEventListModel<Media.SupportedMediaType>( - mediaTypeList); - - mediaTypeJList = new JList(mediaTypeListModel); - DefaultEventSelectionModel<Media.SupportedMediaType> mediaTypeSelectionModel = new DefaultEventSelectionModel<Media.SupportedMediaType>( - mediaTypeList); - - mediaTypeJList.setSelectionModel(mediaTypeSelectionModel); - selectedTypes = mediaTypeSelectionModel.getSelected(); - mediaTypeJList.addListSelectionListener(this); - mediaTypeJList.setCellRenderer(new MediaTypeCellRenderer()); - mediaTypeJList.setBackground(Color.BLACK); - } - - - public JList getJList() { - return mediaTypeJList; - } - - - @Override - public void valueChanged(ListSelectionEvent e) { - Matcher<Media> newMatcher = new MediaForTypeMatcher(selectedTypes); - - fireChanged(newMatcher); - } - - private EventList<Media.SupportedMediaType> mediaTypeList; - private EventList<Media.SupportedMediaType> selectedTypes; - private JList mediaTypeJList; - private static final String[] iconFiles; - private static final String[] activeIconFiles; - static { - iconFiles = new String[] { "images/sr_default.png", "images/sr_music.png", "images/sr_movies.png", - "images/sr_movies_i.png", "images/sr_dvd.png", "images/sr_dvd_i.png", "images/sr_lvdr.png", - "images/sr_lvdr_i.png", "images/sr_vdr.png", "images/sr_vdr_i.png", "images/sr_photos.png", - "images/sr_default.png" }; - activeIconFiles = new String[] { "images/sradefault.png", "images/sramusic.png", "images/sramovies.png", - "images/sramovies_i.png", "images/sradvd.png", "images/sradvd_i.png", "images/sralvdr.png", - "images/sralvdr_i.png", "images/sravdr.png", "images/sravdr_i.png", "images/sraphotos.png", - "images/sradefault.png" }; - } -} diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java deleted file mode 100644 index 4b46a13..0000000 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java +++ /dev/null @@ -1,172 +0,0 @@ -package de.schwarzrot.cmpc.util; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import com.google.gson.stream.JsonReader; -import de.schwarzrot.cmpc.domain.Media; -import de.schwarzrot.cmpc.domain.MediaType; -import de.schwarzrot.cmpc.domain.PlayList; - - -public class MedialistParser { - public PlayList parseListChunk(InputStream is) { - JsonReader reader = null; - PlayList rv = null; - - try { - reader = new JsonReader(new InputStreamReader(is, "UTF-8")); - - rv = readPlayList(reader); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - try { - reader.close(); - } catch (Throwable t) { - } - } - return rv; - } - - - // @Test - public void testJSonParsing() { - FileInputStream fis = null; - - try { - fis = new FileInputStream(new File("test.json")); - parseListChunk(fis); - fis.close(); - fis = null; - } catch (Throwable t) { - t.printStackTrace(); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (Throwable t) { - } - } - } - } - - - protected Media readMedia(JsonReader reader) { - Media rv = new Media(); - - try { - reader.beginObject(); - while (reader.hasNext()) { - String name = reader.nextName(); - - if ("name".equals(name)) { - rv.setName(reader.nextString()); - } else if ("type".equals(name)) { - rv.setType(reader.nextInt()); - } else if ("format".equals(name)) { - rv.setFormat(reader.nextString()); - } else if ("width".equals(name)) { - rv.setWidth(reader.nextInt()); - } else if ("height".equals(name)) { - rv.setHeight(reader.nextInt()); - } else if ("path".equals(name)) { - rv.setPath(reader.nextString()); - } else { - reader.skipValue(); - } - } - reader.endObject(); - } catch (Throwable t) { - t.printStackTrace(); - } - return rv; - } - - - protected List<Media> readMediaArray(JsonReader reader) { - List<Media> rv = new ArrayList<Media>(); - - try { - reader.beginArray(); - while (reader.hasNext()) { - rv.add(readMedia(reader)); - } - reader.endArray(); - } catch (Throwable t) { - t.printStackTrace(); - } - return rv; - } - - - protected MediaType readMediaType(JsonReader reader) { - MediaType rv = new MediaType(); - - try { - reader.beginObject(); - while (reader.hasNext()) { - String name = reader.nextName(); - - if ("name".equals(name)) { - rv.setName(reader.nextString()); - } else if ("start".equals(name)) { - rv.setStart(reader.nextLong()); - } else { - reader.skipValue(); - } - } - reader.endObject(); - } catch (Throwable t) { - t.printStackTrace(); - } - return rv; - } - - - protected PlayList readPlayList(JsonReader reader) { - PlayList rv = new PlayList(); - - try { - reader.beginObject(); - while (reader.hasNext()) { - String name = reader.nextName(); - - if ("total".equals(name)) { - rv.setTotal(reader.nextLong()); - } else if ("types".equals(name)) { - rv.setTypes(readTypeArray(reader)); - } else if ("results".equals(name)) { - rv.setResults(readMediaArray(reader)); - } else { - reader.skipValue(); - } - } - reader.endObject(); - } catch (Throwable t) { - t.printStackTrace(); - rv = null; - } - return rv; - } - - - protected List<MediaType> readTypeArray(JsonReader reader) { - List<MediaType> rv = new ArrayList<MediaType>(); - - try { - reader.beginArray(); - while (reader.hasNext()) { - rv.add(readMediaType(reader)); - } - reader.endArray(); - } catch (Throwable t) { - t.printStackTrace(); - } - return rv; - } -} |
