511d1c1580cbf607069ab4c1b6fb34b6a1602843
1 package be
.nikiroo
.fanfix
.library
;
3 import java
.awt
.image
.BufferedImage
;
5 import java
.io
.IOException
;
6 import java
.util
.ArrayList
;
9 import be
.nikiroo
.fanfix
.Instance
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
11 import be
.nikiroo
.fanfix
.data
.Story
;
12 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
13 import be
.nikiroo
.utils
.Progress
;
14 import be
.nikiroo
.utils
.Version
;
15 import be
.nikiroo
.utils
.serial
.ConnectActionClient
;
18 * This {@link BasicLibrary} will access a remote server to list the available
19 * stories, and download the one you try to load to the local directory
20 * specified in the configuration.
24 public class RemoteLibrary
extends BasicLibrary
{
29 private LocalLibrary lib
;
30 private List
<MetaData
> metas
;
33 * Create a {@link RemoteLibrary} linked to the given server.
36 * the host to contact or NULL for localhost
38 * the port to contact it on
40 public RemoteLibrary(String host
, int port
) {
44 this.baseDir
= Instance
.getRemoteDir(host
);
45 this.baseDir
.mkdirs();
47 this.lib
= new LocalLibrary(baseDir
, OutputType
.INFO_TEXT
,
52 protected List
<MetaData
> getMetas(Progress pg
) {
56 metas
= new ArrayList
<MetaData
>();
59 new ConnectActionClient(host
, port
, true, null) {
61 public void action(Version serverVersion
) throws Exception
{
63 Object rep
= send("GET_METADATA *");
64 for (MetaData meta
: (MetaData
[]) rep
) {
67 } catch (Exception e
) {
72 } catch (IOException e
) {
81 public synchronized File
getFile(final String luid
) {
82 File file
= lib
.getFile(luid
);
84 final File
[] tmp
= new File
[1];
86 new ConnectActionClient(host
, port
, true, null) {
88 public void action(Version serverVersion
) throws Exception
{
90 Object rep
= send("GET_STORY " + luid
);
91 Story story
= (Story
) rep
;
93 lib
.save(story
, luid
, null);
94 tmp
[0] = lib
.getFile(luid
);
96 } catch (Exception e
) {
101 } catch (IOException e
) {
109 MetaData meta
= getInfo(luid
);
117 public BufferedImage
getCover(String luid
) {
118 // Retrieve it from the network if needed:
119 if (lib
.getInfo(luid
) == null) {
123 return lib
.getCover(luid
);
127 protected void clearCache() {
133 public synchronized Story
save(Story story
, String luid
, Progress pg
)
135 throw new java
.lang
.InternalError(
136 "No write support allowed on remote Libraries");
140 protected int getNextId() {
141 throw new java
.lang
.InternalError(
142 "No write support allowed on remote Libraries");
146 protected void doDelete(String luid
) throws IOException
{
147 throw new java
.lang
.InternalError(
148 "No write support allowed on remote Libraries");
152 protected Story
doSave(Story story
, Progress pg
) throws IOException
{
153 throw new java
.lang
.InternalError(
154 "No write support allowed on remote Libraries");